user-0 提问: C语言大佬们救救我这可怜的小学妹吧！啊啊啊！快要疯掉了呀！

回复:
user: user-1
content: 看到学妹我就进来了，看见题目，准备开溜了

user: user-0
content: 引用 10 楼 自信男孩的回复:[quote=引用 8 楼 李Aiden 的回复:] [quote=引用 7 楼 自信男孩的回复:]注意在最后要加上fclose(fp);用于关闭文件 可，谢谢哥哥们[/quote] 你是妹子呢，还是汉子呢，哈哈[/quote] 我是你们心目中最完美的样子

user: user-2
content: 引用 8 楼 李Aiden 的回复:[quote=引用 7 楼 自信男孩的回复:]注意在最后要加上fclose(fp);用于关闭文件 可，谢谢哥哥们[/quote] 你是妹子呢，还是汉子呢，哈哈

user: user-3
content: 引用 4 楼 自信男孩 的回复:{         if (p->average > max->average)         {             max = p;         }         p = p->next;     } 这里内存泄露了，你的max动态申请了空间，然后这里又max = p;那max指向的内存不就找不到了吗？  [quote=引用 3 楼 user-3 的回复:] 小学妹不要慌    #include <stdio.h> #include <stdlib.h> #include <string.h>  struct Stu {     char no[20];     char name[10];     float math;     float political;     float English;     float average;     struct Stu *next; };  int main(void) {     FILE *fp;     fp = fopen("student.txt", "r");     if (!fp)     {         printf("文件打开失败");         exit(0);     }     struct Stu* head = (struct Stu*)malloc(sizeof(struct Stu));     struct Stu* tmp;     head->next = NULL;     char no[20];     char name[10];     float math;     float political;     float English;     float average;     while (fscanf(fp, "%s\t %s\t %f\t %f\t %f\t %f", no, name, &math, &political, &English, &average) != EOF)     {         tmp = (struct Stu*)malloc(sizeof(struct Stu));         tmp->next = NULL;         if (tmp)         {             strcpy(tmp->no, no);             strcpy(tmp->name, name);             tmp->math = math;             tmp->political = political;             tmp->English = English;             tmp->average = average;             tmp->next = head->next;             head->next = tmp;         }     }     struct Stu* max = (struct Stu*)malloc(sizeof(struct Stu));     max->average = 0.0;     struct Stu* p = head->next;     while (p)     {         if (p->average > max->average)         {             max = p;         }         p = p->next;     }     printf("均分最高的学生的姓名是%s,学号是%s\n", max->name, max->no);     return 0; }[/quote]    引用 4 楼 自信男孩 的回复:{         if (p->average > max->average)         {             max = p;         }         p = p->next;     } 这里内存泄露了，你的max动态申请了空间，然后这里又max = p;那max指向的内存不就找不到了吗？  [quote=引用 3 楼 user-3 的回复:] 小学妹不要慌    #include <stdio.h> #include <stdlib.h> #include <string.h>  struct Stu {     char no[20];     char name[10];     float math;     float political;     float English;     float average;     struct Stu *next; };  int main(void) {     FILE *fp;     fp = fopen("student.txt", "r");     if (!fp)     {         printf("文件打开失败");         exit(0);     }     struct Stu* head = (struct Stu*)malloc(sizeof(struct Stu));     struct Stu* tmp;     head->next = NULL;     char no[20];     char name[10];     float math;     float political;     float English;     float average;     while (fscanf(fp, "%s\t %s\t %f\t %f\t %f\t %f", no, name, &math, &political, &English, &average) != EOF)     {         tmp = (struct Stu*)malloc(sizeof(struct Stu));         tmp->next = NULL;         if (tmp)         {             strcpy(tmp->no, no);             strcpy(tmp->name, name);             tmp->math = math;             tmp->political = political;             tmp->English = English;             tmp->average = average;             tmp->next = head->next;             head->next = tmp;         }     }     struct Stu* max = (struct Stu*)malloc(sizeof(struct Stu));     max->average = 0.0;     struct Stu* p = head->next;     while (p)     {         if (p->average > max->average)         {             max = p;         }         p = p->next;     }     printf("均分最高的学生的姓名是%s,学号是%s\n", max->name, max->no);     return 0; }[/quote]   多谢，之前没注意，确实应该改一下 struct Stu* max;     average = 0.0;     struct Stu* p = head->next;     while (p)     {         if (p->average > average)         {             max = p;             average = p->average;         }         p = p->next;     }

user: user-0
content: 引用 7 楼 自信男孩的回复:注意在最后要加上fclose(fp);用于关闭文件 可，谢谢哥哥们

user: user-2
content: 注意在最后要加上fclose(fp);用于关闭文件

user: user-2
content: #include <stdio.h> #include <stdlib.h> #include <string.h>  struct Stu {     char no[20];     char name[10];     float math;     float political;     float English;     float average;     struct Stu *next; };  int main(void) {     FILE *fp;     fp = fopen("student.txt", "r");     if (!fp)     {         printf("文件打开失败");         exit(0);     }     struct Stu* head = (struct Stu*)malloc(sizeof(struct Stu));     struct Stu* tmp;     //head->next = NULL;     char no[20];     char name[10];     float math;     float political;     float English;     float average;      head->next = NULL;     //while (fscanf(fp, "%s\t %s\t %f\t %f\t %f\t %f", no, name, &math, &political, &English, &average) != EOF)     while (fscanf(fp, "%s %s %f %f %f %f\n", no, name, &math, &political, &English, &average) != EOF)     {         tmp = (struct Stu*)malloc(sizeof(struct Stu));         if (!tmp) {             fprintf(stderr, "malloc error!\n");             exit(0);         }         tmp->next = NULL;         //if (tmp)         //{             strcpy(tmp->no, no);             strcpy(tmp->name, name);             tmp->math = math;             tmp->political = political;             tmp->English = English;             tmp->average = average;             tmp->next = head->next;             head->next = tmp;         //}     }     /*     struct Stu* max = (struct Stu*)malloc(sizeof(struct Stu));     max->average = 0.0;     */     struct Stu *max = head->next;     struct Stu* p = head->next;     while (p)     {         if (p->average > max->average)         {             max = p;         }         p = p->next;     }     printf("均分最高的学生的姓名是%s,学号是%s\n", max->name, max->no);      return 0; } 供参考～  借助楼上的代码，改了一下，可以试一下是否可以使用～

user: user-0
content: 哥哥们好厉害(ง •̀_•́)ง

user: user-2
content: {         if (p->average > max->average)         {             max = p;         }         p = p->next;     } 这里内存泄露了，你的max动态申请了空间，然后这里又max = p;那max指向的内存不就找不到了吗？  引用 3 楼 user-3 的回复:小学妹不要慌    #include <stdio.h> #include <stdlib.h> #include <string.h>  struct Stu {     char no[20];     char name[10];     float math;     float political;     float English;     float average;     struct Stu *next; };  int main(void) {     FILE *fp;     fp = fopen("student.txt", "r");     if (!fp)     {         printf("文件打开失败");         exit(0);     }     struct Stu* head = (struct Stu*)malloc(sizeof(struct Stu));     struct Stu* tmp;     head->next = NULL;     char no[20];     char name[10];     float math;     float political;     float English;     float average;     while (fscanf(fp, "%s\t %s\t %f\t %f\t %f\t %f", no, name, &math, &political, &English, &average) != EOF)     {         tmp = (struct Stu*)malloc(sizeof(struct Stu));         tmp->next = NULL;         if (tmp)         {             strcpy(tmp->no, no);             strcpy(tmp->name, name);             tmp->math = math;             tmp->political = political;             tmp->English = English;             tmp->average = average;             tmp->next = head->next;             head->next = tmp;         }     }     struct Stu* max = (struct Stu*)malloc(sizeof(struct Stu));     max->average = 0.0;     struct Stu* p = head->next;     while (p)     {         if (p->average > max->average)         {             max = p;         }         p = p->next;     }     printf("均分最高的学生的姓名是%s,学号是%s\n", max->name, max->no);     return 0; }

user: user-3
content: 小学妹不要慌    #include <stdio.h> #include <stdlib.h> #include <string.h>  struct Stu {     char no[20];     char name[10];     float math;     float political;     float English;     float average;     struct Stu *next; };  int main(void) {     FILE *fp;     fp = fopen("student.txt", "r");     if (!fp)     {         printf("文件打开失败");         exit(0);     }     struct Stu* head = (struct Stu*)malloc(sizeof(struct Stu));     struct Stu* tmp;     head->next = NULL;     char no[20];     char name[10];     float math;     float political;     float English;     float average;     while (fscanf(fp, "%s\t %s\t %f\t %f\t %f\t %f", no, name, &math, &political, &English, &average) != EOF)     {         tmp = (struct Stu*)malloc(sizeof(struct Stu));         tmp->next = NULL;         if (tmp)         {             strcpy(tmp->no, no);             strcpy(tmp->name, name);             tmp->math = math;             tmp->political = political;             tmp->English = English;             tmp->average = average;             tmp->next = head->next;             head->next = tmp;         }     }     struct Stu* max = (struct Stu*)malloc(sizeof(struct Stu));     max->average = 0.0;     struct Stu* p = head->next;     while (p)     {         if (p->average > max->average)         {             max = p;         }         p = p->next;     }     printf("均分最高的学生的姓名是%s,学号是%s\n", max->name, max->no);     return 0; }

user: user-0
content: 引用 1 楼 自信男孩的回复:先自己写写吧，不然怎么提高和进步～ 说是这么说，是真写不出啊

user: user-2
content: 先自己写写吧，不然怎么提高和进步～