C的putchar问题

来源:百度知道 编辑:UC知道 时间:2024/06/07 18:12:21
#include<stdio.h>
main()
{
int c;
while((c=getchar())!=EOF)
putchar(c);
printf("the end!");
}
如上程序,将putchar(c)后;改成,可以输出the end!不然显示不了。我也知道getchar问题,一个一个字符的读和写,但是如何能使c串完全输出后才显示“the end!”?
现在是在改为“,”后每输出一个输入字符就会输出一个the end!
这个办法不错,但是产生一个问题,就是当我没有输入字符,直接回车,这样就会产生一个the end!希望直接回车继续出现提示符而不是the end!

我用的是Trubo c++,ctrl+z之后直接复制了我的输入,而the end!也没有了。之后不出现提示符只好关闭窗体

#include<stdio.h>
main()
{
int c;
while((c=getchar())!=EOF)
{
putchar(c);
if(c=='\n')
printf("the end!");
}
}

///////////////////////
#include<stdio.h>
main()
{
int c;
int i=0;
while((c=getchar())!=EOF)
{
putchar(c);
i++;
if(c=='\n')
{
if(i>1)
printf("the end!");
i=0;
}
}
}

///////////
行不行?行就给我个 最佳 吧

主要在于你的判断条件:
((c=getchar())!=EOF)
在DOS下EOF是用ctrl+Z输入的
你输入完字符后,按Ctrl+Z就行了。