鱼C论坛

 找回密码
 立即注册
查看: 3858|回复: 8

c语言编程 求助

[复制链接]
发表于 2013-4-15 17:46:22 | 显示全部楼层 |阅读模式

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

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

x
哪里错了撒、帮个:D
#include "stdio.h"

struct
{
        int num;
        char name[10];
        char sex;
        char job;
        union
        {
                int c;
                char position[10];
        }categoty;
}person[2];

void main()
{
        int n;
        for (n = 0;n < 2;n++)
        {
                printf("Please enter num:");
                scanf("%d",&person[n].num);

                printf("Please enter name:");
                scanf("%s",&person[n].name[10]);
               
                printf("Please enter sex(M/W):");
                scanf("%s",&person[n].sex);
               
                printf("Please enter job(s/t):");
                scanf("%s",&person[n].job);
                if(person[n].job == 's')
                {
                        printf("Please enter class:");
                        scanf("%d",&person[n].categoty.c);
                }
                else
                {
                        printf("Please enter position:");
                        scanf("%s",&person[n].categoty.position[10]);
                }
                printf("\n");
        }

        printf("num\t name\t sex\t job\t categoty\n");
        for(n = 0;n < 2;n++)
        {
                printf("%d\t",person[n].num);
                printf(" %s\t",person[n].name);
                printf(" %s\t",person[n].sex);
            printf(" %s\t",person[n].job);
                if(person[n].job == 's')
                {
                        printf(" %d",person[n].categoty.c);
                }
                else
                {
                        printf(" %s",person[n].categoty.position[10]);
                }
                printf("\n");
        }
}

小甲鱼最新课程 -> https://ilovefishc.com
发表于 2013-4-15 18:30:27 | 显示全部楼层
楼主看一下你发上去的程序。。冲洗发一下吧。。。
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2013-4-15 20:01:58 | 显示全部楼层
太生气了,无法HOLD啦 >_<......
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2013-4-15 20:22:22 | 显示全部楼层
  1. #include <stdio.h>
  2. #include <string.h>

  3. struct
  4. {
  5.         int num;
  6.         char name[10];
  7.         char sex;
  8.         char job;
  9.         union
  10.         {
  11.                 int c;
  12.                 char position[10];
  13.         }categoty;
  14. }person[2];

  15. int main(void)
  16. {
  17.         int n;
  18.         for (n = 0;n < 2;n++)
  19.         {
  20.                 printf("please enter num:");
  21.                 scanf("%d",&person[n].num);

  22.                 printf("please enter name:");
  23.                 scanf("%s",person[n].name);

  24.                 getchar();  //清空输入缓冲区

  25.                 printf("please enter sex(M/W):");
  26.                 scanf("%c",&person[n].sex);

  27.                 getchar();

  28.                 printf("please enter job(s/t):");
  29.                 scanf("%c",&person[n].job);
  30.                 getchar();
  31.                 if('s' == person[n].job)
  32.                 {
  33.                         printf("please enter class:");
  34.                         scanf("%d",&person[n].categoty.c);
  35.                 }
  36.                 else
  37.                 {
  38.                         printf("please enter position:");
  39.                         scanf("%s",&person[n].categoty.position);
  40.                 }
  41.                 printf("\n");
  42.         }

  43.         printf("num\t name\t sex\t job\t categoty\n");
  44.         for(n = 0;n < 2;n++)
  45.         {
  46.                 printf("%d\t",person[n].num);
  47.                 printf(" %s\t",person[n].name);
  48.                 printf(" %c\t",person[n].sex);
  49.             printf(" %c\t",person[n].job);
  50.                 if(person[n].job == 's')
  51.                 {
  52.                         printf(" %d",person[n].categoty.c);
  53.                 }
  54.                 else
  55.                 {
  56.                         printf(" %s",person[n].categoty.position);
  57.                 }
  58.                 printf("\n");
  59.         }

  60.         return 0;
  61. }
复制代码
这是在楼主的基础之上改的,代码仅供参考。
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2013-4-16 23:44:42 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2013-4-16 23:46:23 | 显示全部楼层
小亮1201 发表于 2013-4-15 20:22
这是在楼主的基础之上改的,代码仅供参考。

非常感谢   
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2013-4-16 23:50:50 | 显示全部楼层
学习了,经常出现的错误!
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2013-4-16 23:52:38 | 显示全部楼层
diouf3 发表于 2013-4-16 23:50
学习了,经常出现的错误!

嗯                         额
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2013-4-18 16:16:14 | 显示全部楼层
我发现我一看到比较长的代码就没信心了
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-8-3 05:09

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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