鱼C论坛

 找回密码
 立即注册
查看: 4870|回复: 5

清屏函数用不了!

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

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

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

x
本帖最后由 dong50252409 于 2011-8-10 12:09 编辑
  1. /* Note:Your choice is C IDE */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #define LEN sizeof(struct student)

  5. struct student
  6. {
  7.         char num[6], name[20], sex[3];//定义学号、姓名、性别
  8.         float math, english, politics, chinese, sum;//定义数学、英语、**、语文、总分
  9.         struct student *next;
  10. };
  11. //菜单
  12. void menu()
  13. {
  14.         system("cls");//清屏
  15.         printf("-------------------------------------------------------------------------------");
  16.         printf("\n                                 学生数据管理系统\n");
  17.         printf("\n                         [0]退出\n");
  18.         printf("\n                         [1]创建学生数据\n");
  19.         printf("\n                         [2]添加学生数据\n");
  20.         printf("\n                         [3]删除学生数据\n");
  21.         printf("\n                         [4]查询\n");
  22.         printf("-------------------------------------------------------------------------------");
  23.         
  24. }
  25. // 等待用户按回车后回到主菜单
  26. void to_menu()
  27. {
  28. char c1, c2;
  29. printf("\n\n\n按回车键返回主菜单...");
  30. scanf("%c%c",&c1,&c2);//第一个字符吸收上次的确认回车键
  31. menu();
  32. }
  33. //录入学生输入
  34. struct student *init(int n)
  35. {
  36.         int i;
  37.         struct student *head, *p, *s;
  38.         for(i = 1;i <= n;i++)
  39.         {
  40.                 if(i == 1)
  41.                 {
  42.                         printf("\n请输入第%d个学生信息:",i);
  43.                         p = (struct student *)malloc(LEN);//开辟存储单元
  44.                         printf("\n学号:");
  45.                         scanf("%s",&p->num);
  46.                         printf("\n姓名:");
  47.                         scanf("%s",&p->name);
  48.                         printf("\n性别:");
  49.                         scanf("%s",&p->sex);
  50.                         printf("\n数学成绩:");
  51.                         scanf("%f",&p->math);
  52.                         printf("\n英语成绩:");
  53.                         scanf("%f",&p->english);
  54.                         printf("\n**:");
  55.                         scanf("%f",&p->politics);
  56.                         printf("\n语文成绩:");
  57.                         scanf("%f",&p->chinese);
  58.                         p->sum = p->math + p->english + p->politics + p->chinese;
  59.                         printf("\n学号\t姓名\t性别\t数学\t英语\t**\t语文\t总分\n");
  60.                         printf("------------------------------------------------------------\n");
  61.                         printf("%s\t%s\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n",p->num, p->name, p->sex, p->math, p->english, p->politics, p->chinese, p->sum);
  62.                         head = p;
  63.                         if(n == 1) p->next = NULL;
  64.                 }
  65.                         
  66.                 else
  67.                 {
  68.                         printf("\n请输入第%d个学生信息:",i);
  69.                         s = (struct student *)malloc(LEN);
  70.                         printf("\n学号:");
  71.                         scanf("%s",&s->num);
  72.                         printf("\n姓名:");
  73.                         scanf("%s",&s->name);
  74.                         printf("\n性别:");
  75.                         scanf("%s",&s->sex);
  76.                         printf("\n数学成绩:");
  77.                         scanf("%f",&s->math);
  78.                         printf("\n英语成绩:");
  79.                         scanf("%f",&s->english);
  80.                         printf("\n**:");
  81.                         scanf("%f",&s->politics);
  82.                         printf("\n语文成绩:");
  83.                         scanf("%f",&s->chinese);
  84.                         s->sum = s->math + s->english + s->politics + s->chinese;
  85.                         printf("\n学号\t姓名\t性别\t数学\t英语\t**\t语文\t总分\n");
  86.                         printf("------------------------------------------------------------\n");
  87.                         printf("%s\t%s\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n",s->num, s->name, s->sex, s->math, s->english, s->politics, s->chinese, s->sum);
  88.                         p->next = s;
  89.                         p = s;
  90.                         s->next = NULL;
  91.                 }
  92.         }
  93.         return head;
  94. }
  95. //添加学生数据
  96. void insert(struct student *head)
  97. {
  98.         struct student *p, *pi;
  99.         char num[6];
  100.         printf("\n请问要在哪个学生后面插入数据(输入学号):");
  101.         scanf("%s",num);
  102.         pi = (struct student *)malloc(LEN);
  103.         p = head;
  104.         printf("\n学号:");
  105.         scanf("%s",&pi->num);
  106.         printf("\n姓名:");
  107.         scanf("%s",&pi->name);
  108.         printf("\n性别:");
  109.         scanf("%s",&pi->sex);
  110.         printf("\n数学成绩:");
  111.         scanf("%f",&pi->math);
  112.         printf("\n英语成绩:");
  113.         scanf("%f",&pi->english);
  114.         printf("\n**:");
  115.         scanf("%f",&pi->politics);
  116.         printf("\n语文成绩:");
  117.         scanf("%f",&pi->chinese);
  118.         pi->sum = pi->math + pi->english + pi->politics + pi->chinese;
  119.         if(head == NULL)
  120.         {
  121.                 head = pi;
  122.                 pi->next = NULL;
  123.         }
  124.         else
  125.         {
  126.                 while((p->num != num) && (p->next != NULL))
  127.                 {
  128.                         p = p->next;
  129.                 }
  130.                 if(p->next != NULL)
  131.                 {
  132.                         pi->next = p->next;
  133.                         p->next = pi;
  134.                 }
  135.                 else
  136.                 {
  137.                         p->next = pi;
  138.                         pi->next = NULL;
  139.                 }
  140.         }
  141. }
  142. //删除学生数据
  143. struct student *del(struct student *head, char n[6])
  144. {
  145.         struct student *p, *q;
  146.         p = head;
  147.         if(head = NULL)
  148.         {
  149.                 printf("\n没有学生的资料要删除!");
  150.                 return head;
  151.         }
  152.         while(p->num != n && p->next != NULL)
  153.         {
  154.                 q = p;
  155.                 p = p->next;
  156.         }
  157.         if(p->num == n)
  158.         {
  159.                 if(p == head)
  160.                 {
  161.                         head = p->next;
  162.                 }
  163.                 else
  164.                 {
  165.                         q->next = p->next;
  166.                
  167.                 }
  168.                 free(p);
  169.         }
  170.         else
  171.         {
  172.                 printf("\n找不到相应的学生资料!");
  173.         }
  174.         return head;
  175. }
  176. //列表
  177. void list(struct student *head)
  178. {
  179.         int i = 0;
  180.         struct student *p;
  181.         p = head;
  182.         printf("\n学号\t姓名\t性别\t数学\t英语\t**\t语文\n");
  183.         printf("----------------------------------------------------\n");
  184.         while(p != NULL)
  185.         {
  186.                 printf("%s\t%s\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n",p->num, p->name, p->sex, p->math, p->english, p->politics, p->chinese, p->sum);
  187.                 p = p->next;
  188.         }
  189.         printf("----------------------------------------------------\n");
  190. }
  191. //保存
  192. void save(struct student *head)
  193. {
  194.         FILE *fp;
  195.         struct student *p;
  196.         p = head;
  197.         if((fp = fopen("stu_list","wb")) == NULL)
  198.         {
  199.                 printf("\n不能打开指定文件!");
  200.                 to_menu();
  201.         }
  202.         while(p)
  203.         {
  204.                 fwrite(p, sizeof(struct student), 1, fp);
  205.                 p = p->next;
  206.         }
  207.         fclose(fp);
  208.         
  209. }
  210. //读取
  211. struct student *read()
  212. {
  213.         FILE *fp;
  214.         struct student *p;//工作指针
  215.         struct student *last, *head;//最后一项指针
  216.         head = (struct student*)malloc(LEN);
  217.         last = head;
  218.         if((fp = fopen("stu_list","rb")) == NULL)
  219.         {
  220.                 printf("\n不能打开指定文件!");
  221.                 to_menu();
  222.         }
  223.         while(!feof(fp))
  224.         {
  225.                 p = (struct student *)malloc(LEN);
  226.                 if(fread(p, sizeof(struct student), 1, fp) == 1)
  227.                 {
  228.                         last->next = p;
  229.                         last = last->next;
  230.                 }
  231.         }
  232.         fclose(fp);
  233.         return head = head->next;
  234. }
  235. //主函数
  236. void main()
  237. {
  238.     char fun;
  239.     int n;
  240.     struct student *head;
  241.     menu();
  242.     printf("\n请输入功能号[0-4]:");
  243.     while((fun = tolower(getchar())) != '0')
  244.     {
  245.             switch(fun)
  246.             {
  247.                     case '1':
  248.                     {
  249.                             printf("\n请输入班级总人数:");
  250.                             scanf("%d",&n);
  251.                             head = init(n);
  252.                             list(head);
  253.                             save(head);
  254.                             break;
  255.                     }
  256.                     case '2':
  257.                     {
  258.                             insert(head);
  259.                             list(head);
  260.                             save(head);
  261.                             break;
  262.                     }
  263.                     case '3':
  264.                     {
  265.                             char num[6];
  266.                             printf("\n请输入要删除学生的学号:");
  267.                             scanf("%s",num);
  268.                             head = del(head,num);
  269.                             list(head);
  270.                             save(head);
  271.                             break;
  272.                     }
  273.             }
  274.     }
  275. }
复制代码
不能加入清屏函数 一加入就报错
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-8-7 23:17:39 | 显示全部楼层
例如在36行98行145加入system(cls);就各种报错 都不知道哪来的
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-8-8 00:41:00 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-8-8 08:24:52 | 显示全部楼层
15行的清屏函数就好使 不报错
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-8-8 08:50:20 | 显示全部楼层
我这里没有报错.

未命名.jpg
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-8-8 10:21:22 | 显示全部楼层
这就奇怪了
小甲鱼最新课程 -> 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.

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