鱼C论坛

 找回密码
 立即注册
查看: 2943|回复: 2

共同体代码求改成 不限人数的

[复制链接]
发表于 2012-8-13 17:09:33 | 显示全部楼层 |阅读模式

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

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

x
共同体代码求改成  不限人数的

#include <stdio.h>
struct
{
      int num;
      char name[10];
      char sex;
      char job;
      union
      {
            int banji;
            char position[10];
      }category;
}person[2];  //为了方便先假设一个学生一个老师。
void main()
{
      int i;
      for(i=0; i < 2; i++)
      {
            printf("Please input the num: ");
            scanf("%d", &person[i].num);
            printf("Please input the name: ");
            scanf("%s", person[i].name);
            fflush(stdin);
            printf("Please input the sex(M/F): ");
            scanf("%c", &person[i].sex);
            fflush(stdin);
            printf("Please input the job(s/t): ");
            scanf("%c", &person[i].job);
            fflush(stdin);
            if( person[i].job == 's' )
            {
                  printf("Please input the class: ");
                  scanf("%d", &person[i].category.banji);
                  fflush(stdin);
            }
            else if( person[i].job == 't' )
            {
                  printf("Please input the position: ");
                  scanf("%s", person[i].category.position);
                  fflush(stdin);
            }
            else
            {
                  printf("Input Error!!\n");
            }            
            
            printf("\n");
      }
      
      // 以下是打印数据……
      printf("No.    name    sex job class/position\n");
      for( i=0; i < 2; i++ )
      {
            if( person[i].job == 's')
            {
                  printf("%-6d%-10s%-3c%-3c%10d\n", person[i].num,
                        person[i].name, person[i].sex, person[i].job,
                        person[i].category.banji);
            }
            else
            {
                  printf("%-6d%-10s%-3c%-3c%10s\n", person[i].num,
                        person[i].name, person[i].sex, person[i].job,
                        person[i].category.position);
            }
      }
}



求高手 帮下    给个思路也可以
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2012-8-13 18:00:47 | 显示全部楼层
:dizzy:没人帮下啊
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2012-8-14 09:40:31 | 显示全部楼层
改成链表咯
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-4-26 14:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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