700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > c语言输入字符串 Eof C语言多行字符串eof问题如何解决?

c语言输入字符串 Eof C语言多行字符串eof问题如何解决?

时间:2019-04-13 02:43:30

相关推荐

c语言输入字符串 Eof C语言多行字符串eof问题如何解决?

C语言多行字符串eof问题如何解决?

#include

void main()

{ printf("input a sentence \n");

char a[80],*p;

int i=0,lowercase=0,uppercase=0,space=0,tab=0,enter=0;

printf("ps: input ctrl+z to end of the input and press enter to show the result\n");

printf("=====================================\n");

while(1)

{ if((a[i]=getchar())==EOF)

break;

i++;

}

p=&a[0];

while(1)

{if(*p==EOF)

break;

if((*p>='a')&&(*p<='z'))

lowercase++;

else if(*p==' ')

space++;

else if(*p==' ')

tab++;

else if(*p=='\n')

enter++;

else if((*p>='A')&&(*p<='Z'))

uppercase++;

p++;

}

printf("=====================================\n");

printf("lowercase %d\n",lowercase);

printf("uppercase %d\n",uppercase);

printf("space %d\n",space);

printf("tab %d\n",tab);

printf("enter %d\n",enter);

}

程序已经算是成功了

可是有很多让我不爽的地方

首先是ctrl+z必须在行首输入

然后就是当输入ctrl+z之后 还需要输入回车才会显示结果

高手们能不能帮忙改改

让一旦输入ctrl+z 就能使之输出结果

而且因为输入ctrl+z结束时需要按回车 似乎enter的统计也有问题

古冶

发布

2个回答

精华知识

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。