一个简单的结构体例题

来源:互联网 发布:nsis error修复软件 编辑:程序博客网 时间:2024/05/08 01:01
#include<stdio.h>  #include<stdlib.h>  #include<string.h>    struct STI  {      char id[9];      char name[17];      char sex;      char age;      float score;  };    int inutStudentInformation(struct STI *st,int maxCount);        //struct STI *st = stu1;    void showAllStudentInformation(struct STI *s,int count);  void showOneStudentInformation(struct STI stu);      void showOneStudentInformation(struct STI stu)  {      printf("%8s %-16s %4s %4d %f\n",          stu.id,stu.name,stu.sex == 1 ? "男":"女",stu.age,stu.score);  }      void showAllStudentInformation(struct STI *s,int count)  {      int i;        printf("学生信息\n");      printf("%8s %-16s %4s %4s %s\n","学号","姓名","性别","年龄","成绩");      for(i = 0;i < count;i++)      {          showOneStudentInformation(s[i]);      }  }    int inputStudentInformation(struct STI *st,int maxCount)  {      int cnt = 0;      char id[9];      char name[17];      int sex;      int age;      float score;        printf("请输入学号(学号为空,结束输入):");      gets(id);      while(*id != 0)      {          strcpy(st[cnt].id, id);          printf("请输入姓名");          flushall();          gets(name);            printf("请输入性别(1表示男,0表示女):");          scanf("%d",&sex);          st[cnt].sex = (sex == 1 ? 'm' : 'f');            printf("请输入年龄");          scanf("%d",&age);          st[cnt].age = age;                              printf("请输入成绩");          scanf("%lf",&score);          st[cnt].score = score;            printf("请输入学号(学号为空,结束输入):");          flushall();          gets(id);            cnt++;      }        return cnt;  }    void main(void)  {      struct STI stu1[50] ={0};      int count1 = 0;          //先实现信息的录入(填充内容)      count1 = inputStudentInformation(stu1, 50);      showAllStudentInformation(stu1,count1);       }  

0 0
原创粉丝点击