| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 427 人关注过本帖
标题:程序无法输入字符类型数据
只看楼主 加入收藏
zhq825815977
Rank: 1
等 级:新手上路
帖 子:18
专家分:4
注 册:2010-7-12
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
程序无法输入字符类型数据



#include<stdio.h>
#include<string.h>
    struct worker
    {
        int number;
        char name[20];
        char sex[4];
        int born;
        char edu[10];
        char duty[20];
        int pay;
        char addr[15];
        int tele;
    };

    int i=0;
    void shuru(struct worker wor[]);
    void shuchu(struct worker wor[]);
    void chaxun(struct worker wor[]);
    void shanchu(struct worker wor[]);
    void tianjia(struct worker wor[]);

    main()
    {
        struct worker wor[50];
        int a;

        do
        {
            printf("******欢迎进入本系统******\n");
            printf("1.输入信息\n2.输出信息\n3.查询信息\n4.添加信息\n5.删除信息\n0.退出\n");
            scanf("%d",&a);
            switch(a)
            {
            case 1:shuru(wor);
                break;
            case 2:shuchu(wor);
                break;
            case 3:chaxun(wor);
                break;
            case 4:tianjia(wor);
                break;
            case 5:shanchu(wor);
                break;
            case 0:
                break;
            }
        }while(a!=0);
        printf("谢谢!\n");
    }  


    void shuru(struct worker wor[])
    {
        char b;
        printf("********请输入职工信息********\n");
        do
        {
   
            printf("请输入职工号:");
            scanf("\n%d",&wor[i].number);

            printf("请输入职工姓名:");
            scanf("\n%s",wor[i].name);
        
            printf("请输入职工性别:");
            scanf("\n%s",wor[i].sex);
        
            printf("请输入职工出生年月:");
            scanf("\n%d",&wor[i].born);
        
            printf("请输入职工学历:");
            scanf("\n%s",wor[i].edu);
        
            printf("请输入职工职务:");
            scanf("\n%s",wor[i].duty);
        
            printf("请输入职工工资:");
            scanf("\n%d",&wor[i].pay);
        
            printf("请输入职工地址:");
            scanf("\n%s",wor[i].addr);
        
            printf("请输入职工电话:");
            scanf("\n%d",&wor[i].tele);
            
            i++;
        
            printf("是否继续\n(Y/N)");
            fflush(stdin);
            scanf("%c",&b);
        }while(b=='Y'||b=='y');
        shuchu(wor);
    }


    void shuchu(struct worker wor[])
    {
        int k;
        for(k=0;k<i;k++)
        {
            printf("职工号:%d\n",wor[k].number);
            printf("姓名:%c\n",wor[k].name);
            printf("性别:%c\n",wor[k].sex);
            printf("出生年月:%d\n",wor[k].born);
            printf("学历:%c\n",wor[k].edu);
            printf("职务:%c\n",wor[k].duty);
            printf("工资:%d\n",wor[k].pay);
            printf("地址:%c\n",wor[k].addr);
            printf("电话:%d\n",wor[k].tele);
        }
    }

   
    void shanchu(struct worker wor[])
    {
        int x,j,k;
        printf("请输入要删除的职工号:");
        scanf("%d",&x);
        for(j=0;j<i;j++)
        {
            if(x==wor[j].number)
            {
                break;
            }
        }
        if(j<i)
        {
            for(k=j;k<i-1;k++)
            {
                wor[j]=wor[j+1];
            }
            printf("删除的职工信息\n");
            shuchu(wor);
        }
        else
        {
            printf("没有您要删除的职工\n");
            shuchu(wor);
        }
    }

   
    void tianjia(struct worker wor[])
    {
        printf("请输入职工号:");
        scanf("\n%d",&wor[i++].number);
        
        printf("请输入职工姓名:");
        scanf("\n%s",wor[i++].name);
        
        printf("请输入职工性别:");
        scanf("\n%s",wor[i++].sex);

        printf("请输入职工出生年月:");
        scanf("\n%d",&wor[i++].born);
            
        printf("请输入职工学历:");
        scanf("\n%s",wor[i++].edu);
            
        printf("请输入职工职务:");
        scanf("\n%s",wor[i++].duty);
            
        printf("请输入职工工资:");
        scanf("\n%d",&wor[i++].pay);
            
        printf("请输入职工地址:");
        scanf("\n%s",wor[i++].addr);
            
        printf("请输入职工电话:");
        scanf("\n%d",&wor[i++].tele);
    }
无法输入字符类型数据,如何解决,谢谢~~~~~~~~
搜索更多相关主题的帖子: 字符 类型 数据 输入 
2010-07-12 14:51
do8do8do8
Rank: 10Rank: 10Rank: 10
来 自:沙滩
等 级:贵宾
威 望:17
帖 子:366
专家分:1845
注 册:2010-7-2
收藏
得分:20 
printf("职工号:%d\n",wor[k].number);
 printf("姓名:%c\n",wor[k].name);
 printf("性别:%c\n",wor[k].sex);
printf("出生年月:%d\n",wor[k].born);
printf("学历:%c\n",wor[k].edu);
 printf("职务:%c\n",wor[k].duty);
 printf("工资:%d\n",wor[k].pay);
 printf("地址:%c\n",wor[k].addr);
  printf("电话:%d\n",wor[k].tele);
把上面的%c全都改成%s

学C语言从底层开始,学编程从问题开始,一日学会C!!!
2010-07-12 15:28
zhq825815977
Rank: 1
等 级:新手上路
帖 子:18
专家分:4
注 册:2010-7-12
收藏
得分:0 
知道了,非常感谢~~~~~~~
2010-07-12 15:30
zhq825815977
Rank: 1
等 级:新手上路
帖 子:18
专家分:4
注 册:2010-7-12
收藏
得分:0 
刚看到~~~~想了好久~~~~
2010-07-12 15:32
毕业旅行
Rank: 4
等 级:业余侠客
威 望:1
帖 子:130
专家分:280
注 册:2010-7-7
收藏
得分:0 
shuchu()函数里的输出格式都是%c...
2010-07-12 15:37
快速回复:程序无法输入字符类型数据
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024457 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved