鱼C论坛

 找回密码
 立即注册
查看: 2499|回复: 3

程序编译没错误 运行不出预期结果?帮我调试一下 ~还不太会调试程序

[复制链接]
发表于 2012-3-29 19:35:32 | 显示全部楼层 |阅读模式

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

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

x
#include <stdio.h>
void main()
{
char c;
printf("input a character:\n");
c=getchar();
while(c!=0)
{    if(c<32)
      printf("This is a contronl character\n");
    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");
    else
      printf("This is an other character\n");
   printf("input a character:\n");
       c=getchar();
   
}
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2012-3-29 19:43:22 | 显示全部楼层
  1. #include <stdio.h>
  2. void main()
  3. {
  4.         char c;
  5.         printf("input a character:\n");
  6.         c=getchar();
  7.         //while(c!=0)
  8.         while(c!=EOF)
  9.         {   
  10.                 if(c<32)
  11.                         printf("This is a contronl character\n");
  12.                 else if(c>='0'&&c<='9')
  13.                         printf("This is a digit\n");
  14.                 else if(c>='A'&&c<='Z')
  15.                         printf("This is a capital letter\n");
  16.                 else if(c>='a'&&c<='z')
  17.                         printf("This is a small letter\n");
  18.                 else
  19.                         printf("This is an other character\n");
  20.                 printf("input a character:\n");
  21.                 getchar();//吃掉换行
  22.                 c=getchar();   
  23.         }
  24. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2012-3-29 20:05:12 | 显示全部楼层
吃掉\n就行,否则会多执行一次\n字符
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2012-3-30 11:49:24 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-4-20 11:00

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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