【发布时间】:2013-08-06 07:11:09
【问题描述】:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char a,b;
printf("enter the firstkeyword \n");
a = getchar();
printf("enter your second keyword \n");
b = getchar();
if(a>b)
{
printf("it is '%c' greater than '%c' as i expected \n",a,b);
}
else if (b>a)
{
printf("here'%c'is greater than '%c' \n",b,a);
}
else
{
printf("dont type the same character twice in next session \n");
}
return(0);
}
程序编译后的o/p为:
输入第一个关键字
我输入了 '$' 并使用 ctrl+z 到 eof 和 'enter' 继续程序。但即使没有输入第二个关键字,编译器也会将输出打印为
输入您的第二个关键字
正如我所料,它是 '$' 大于 '->'
谁能帮助这个程序?
如有任何语法或短语错误,请见谅。
【问题讨论】:
-
请打开所有编译器警告,并学习使用调试器(在 Linux 上:使用
gcc -Wall -g编译,使用gdb进行调试)。 -
@chintusrikanth 正在读取的下一个字符是
'\n',因为您也在按 Enter 键 -
@BasileStarynkevitch:你在 OP 的源代码中发现任何错误吗?
标签: c compilation output getchar