鱼C论坛

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

[已解决]在连续判断else if中,为什么这个代码运行不了?

[复制链接]
发表于 2018-8-4 12:11:59 | 显示全部楼层 |阅读模式

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

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

x
#include <stdio.h>
int main()
{
        char c;
        printf("input a character: ");
        c=getcher();
        if(c<32)
        {
                printf("This is a control character!");
        }
        else if(c>='0' && c<='9')
        {
                printf("This is a digit\n");
        }
        else if(c>='A'  && c<='Z')
        {
                printf("This is a capital letter!\n");
        }
        else if(c>='a' && c<='z')
        {
                printf("This is a small letter!\n");
        }
}
最佳答案
2018-8-5 12:00:17
#include <stdio.h>
int main()
{
        char c;
        printf("input a character: ");
        c=getchar();//getcher 改为getchar
        if(c<32)
        {
                printf("This is a control character!");
        }
        else if(c>='0' && c<='9')
        {
                printf("This is a digit\n");
        }
        else if(c>='A'  && c<='Z')
        {
                printf("This is a capital letter!\n");
        }
        else if(c>='a' && c<='z')
        {
                printf("This is a small letter!\n");
        }
        return 0;//结尾加上因为是int main
}
else if.PNG
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-8-4 12:18:09 | 显示全部楼层
第6行打错。
由于c支持默认int,所以语法检查pass了。
但是由于编译器找不到getcher本体,报错退出。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-4 12:32:09 | 显示全部楼层
我没有看错,是getcher
getcher
getcher

https://fishc.com.cn/forum.php?m ... peid%26typeid%3D583
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-4 13:12:15 | 显示全部楼层
return 0;呢??
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-4 13:27:21 | 显示全部楼层
getcher 变成 getchar

最后加 return 0;
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2018-8-5 12:00:17 | 显示全部楼层    本楼为最佳答案   
#include <stdio.h>
int main()
{
        char c;
        printf("input a character: ");
        c=getchar();//getcher 改为getchar
        if(c<32)
        {
                printf("This is a control character!");
        }
        else if(c>='0' && c<='9')
        {
                printf("This is a digit\n");
        }
        else if(c>='A'  && c<='Z')
        {
                printf("This is a capital letter!\n");
        }
        else if(c>='a' && c<='z')
        {
                printf("This is a small letter!\n");
        }
        return 0;//结尾加上因为是int main
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-10-2 08:30

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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