user-0 提问: 请教大佬帮我看看代码为什么打印不出嵌套结构体的内容？要怎么修改

回复:
user: user-1
content: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h>  void save(char *name, int n); int readout(char *name, char *type); void outwait(char *name); void deletefile(char*name);   //声明定义结构体 struct student_info {     char name[30];     char ifbook[5];     int cnt;     struct bookman{         char waitname[30];     }book[40]; } info[170];  //char filename[50] = "D:\\progra.txt"; char filename[50] = "a.txt"; char type[10]; char *p;  void save(char *name, int n) {     FILE *fp;     int i;     if ((fp = fopen(name, "w")) == NULL) {         printf("文件打开错误\n");         exit(0);     }     for (i = 0; i < n; i++) {         if (fwrite(&info[i], sizeof(struct student_info), 1, fp) != 1)             printf("文件写入错误");     }     fclose(fp);     printf("Write successfully!\n"); } int readout(char *name, char *type) {     int i,a;     FILE *fp;     if ((fp = fopen(name, type)) == NULL) {         printf("文件打开错误\n");         system("pause");         exit(0);     }      printf("\n=================================\n");     printf(" 名称\t是否预约 *\n");     for (i = 0; fread(&info[i], sizeof (struct student_info), 1, fp) != 0; i++) {         printf("%s\t  %s*\n", info[i].name, info[i].ifbook);     }     printf("=========================================\n");     printf("共有 %d 条记录\n\n", i);     fclose(fp);     return i; } void deletefile(char *name) {     FILE *fp;     int choice;     char delfilename[50];     printf("确定删除当前文件?\n");     printf("1、确定    2、取消\n您的选择是：");     scanf("%d", &choice);     switch (choice) {         case 1:             printf("确定\n");             if (remove(filename) == 0)                 printf("文件删除成功!\n");             else                 printf("文件删除失败!\n");             break;         case 2:             printf("取消\n");             break;         default:             printf("选择错误 !\n");             break;     } }  void outwait(char*name) {     char find[30];     int i, l, number;     strcpy(type, "r");     number = readout(filename, type);     /*     FILE *fp;     if ((fp = fopen(name, "r")) == NULL)     {         printf("文件打开错误\n");         system("pause");     }     */     printf("Read info number = %d\n", number);     printf("请输入名称：");     scanf("%s", find);     printf("预约名单如下\n名称\n");     for ( i = 0; i < number; i++)     {         if(strcmp(find,info[i].name)==0)         {             printf("%d\n", i);             printf("wait number = %d\n", info[i].cnt);             for (l = 0; l < info[i].cnt; l++) {                 printf("%s\n", info[i].book[l].waitname);             }          }     }     printf("\n%d",l);     //fclose(fp); } int main() {     int i, n,choice,l,t;     char boname[30];     int y,m,d;     printf("请输入您要添加的个数：");     scanf("%d", &n);     printf("\n您将会将 %d 信息记录存储到 %s 文件中\n\n", n, filename);      for (i = 0; i < n; i++) {         printf("请输入名称:");         scanf("%s",info[i].name);         printf("\n是否有人预约\n【1】有\t【2】无\n您的选择是：");         scanf("%d",&choice);         switch(choice){             case 1:                 {                     strcpy(info[i].ifbook,"是");                     printf("请输入您要添加的预约人数:");                     scanf("%d",&t);                     info[i].cnt = t;                     for(l=0;l<t;l++)                     {                         printf("\n请输入预约人名字：");                         scanf("%s",info[i].book[l].waitname);                      }                     break;                 }             case 2:                 {                     strcpy(info[i].ifbook,"否");                     break;                 }         }     }     save(filename, n);     outwait(filename);     deletefile(filename); }  参考一下吧  readout已经将waitname从文件里读取到了，不需要再次通过fread读取。 个人建议所有的操作都在内存里进行，而不用实时的去文件里读取

user: user-2
content: 调试是基本功