鱼C论坛

 找回密码
 立即注册
查看: 3367|回复: 3

求帮忙 不知道什么问题

 关闭 [复制链接]
发表于 2011-8-9 08:35:23 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 dong50252409 于 2011-8-10 12:10 编辑
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3. #define LEN sizeof(struct student)

  4. struct student
  5. {
  6.         char num[6], name[20], sex[3];//定义学号、姓名、性别
  7.         float math, english, politics, chinese, sum;//定义数学、英语、**、语文、总分
  8.         struct student *next;
  9. };

  10. int n;//全局变量,用于记录每个班级学生人数

  11. void main()
  12. {
  13.         FILE *fp;
  14.         struct student *p1,*p2,*head;
  15.         char c_name[20];//存放班级名
  16.         char ch;//判定是否继续输入学生信息

  17.         n = 0;
  18.         printf("\n请输入班级名:");
  19.         scanf("%s",c_name);
  20.         fp = fopen(c_name,'wb+');
  21.         p1 = p2 = (struct student *)malloc(LEN);
  22.         head = NULL;
  23.         while(1)
  24.         {        
  25.                 n++;
  26.                 if(n == 1)
  27.                 {
  28.                         printf("\n学号:");
  29.                         scanf("%s",&p1->num);
  30.                         printf("\n姓名:");
  31.                         scanf("%s",&p1->name);
  32.                         printf("\n性别:");
  33.                         scanf("%s",&p1->sex);
  34.                         printf("\n数学成绩:");
  35.                         scanf("%f",&p1->math);
  36.                         printf("\n英语成绩:");
  37.                         scanf("%f",&p1->english);
  38.                         printf("\n**:");
  39.                         scanf("%f",&p1->politics);
  40.                         printf("\n语文成绩:");
  41.                         scanf("%f",&p1->chinese);
  42.                         p1->sum = p1->math + p1->english + p1->politics + p1->chinese;
  43.                         printf("\n学号\t姓名\t性别\t数学\t英语\t**\t语文\t总分\n");
  44.                         printf("------------------------------------------------------------\n");
  45.                         printf("%s\t%s\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n",p1->num, p1->name, p1->sex, p1->math, p1->english, p1->politics, p1->chinese, p1->sum);
  46.                         head = p1;
  47.                         printf("输入0结束,回车继续输入!");
  48.                         scanf("%c",ch);
  49.                         if(ch == '0')
  50.                         {
  51.                                 break;
  52.                         }
  53.                 }
  54.                 else
  55.                 {
  56.                         p1 = p2 = (struct student *)malloc(LEN);
  57.                         printf("\n学号:");
  58.                         scanf("%s",&p1->num);
  59.                         printf("\n姓名:");
  60.                         scanf("%s",&p1->name);
  61.                         printf("\n性别:");
  62.                         scanf("%s",&p1->sex);
  63.                         printf("\n数学成绩:");
  64.                         scanf("%f",&p1->math);
  65.                         printf("\n英语成绩:");
  66.                         scanf("%f",&p1->english);
  67.                         printf("\n**:");
  68.                         scanf("%f",&p1->politics);
  69.                         printf("\n语文成绩:");
  70.                         scanf("%f",&p1->chinese);
  71.                         p1->sum = p1->math + p1->english + p1->politics + p1->chinese;
  72.                         printf("\n学号\t姓名\t性别\t数学\t英语\t**\t语文\t总分\n");
  73.                         printf("------------------------------------------------------------\n");
  74.                         printf("%s\t%s\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n",p1->num, p1->name, p1->sex, p1->math, p1->english, p1->politics, p1->chinese, p1->sum);
  75.                         p2 = p1;
  76.                         p2->next = p1;
  77.                         printf("输入0结束,回车继续输入!");
  78.                         scanf("%c",ch);
  79.                         if(ch == '0')
  80.                         {
  81.                                 break;
  82.                         }
  83.                 }
  84.         }
  85.         p2->next= NULL;
  86.         fclose(fp);
  87. }
复制代码
C:\Users\DY\Desktop\C源代码\新建文本文档.c(24) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'const int '
C:\Users\DY\Desktop\C源代码\新建文本文档.c(24) : warning C4024: 'fopen' : different types for formal and actual parameter 2
C:\Users\DY\Desktop\C源代码\新建文本文档.c(52) : warning C4700: local variable 'ch' used without having been initialized

新建文本文档.obj - 0 error(s), 0 warning(s)
输入完班级名程序就崩溃
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-8-9 08:47:41 | 显示全部楼层
函数参数要求为char类型指针
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-8-9 08:50:14 | 显示全部楼层
没明白 你说的太模糊了
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-8-9 12:38:58 | 显示全部楼层
太模糊了
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-7 13:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表