我想在选择1的文件中输入内容后返回选项

时间:2017-11-01 03:36:47

标签: c

我需要能够选择1,在文件中添加记录,然后返回菜单再做一个选项。我还需要能够做出选择2。

  

代码段

while(program == 1){
            while(menu == 1){
                    num = 0;
                    printf("(1)Add record, (2)View records, or (3)Quit.\n");
                    scanf("%d", &choice);


                    if(choice == 1){
                            menu =0;
                            inv = fopen("recs", "w");
                                            printf("<Item Number> <Item Category> <cost> <city> <date>\n");
                                            fscanf(inv, "%d %c %c %c %c %c %c %c %c %c %c %.2f %c %c %c %c %c %c$
                                            &cost, &city[0], &city[1], &city[2], &city[3], &city[4], &city[5], &$
                            fclose(inv);
                            if(num >= 1){
                                    menu =1;
                                    continue;
                            }
                    }

                    else if(choice == 2){
                            menu =0;
                            int c;
                            inv = fopen("recs", "r");
                            if(inv){
                                    while((c = getc(inv)) != EOF)
                                            putchar(c);
                                    fclose(inv);
                            }
                    }

                    else if(choice == 3){
                            printf("Iventory program terminated\n");
                            menu = 0;
                            program =0;
                            break;
                    }

                    else;
            }
    }
     return(0);
}

1 个答案:

答案 0 :(得分:0)

删除menu = 0;以防万一。它可以正常工作。