#include<stdio.h>
int main()
{
char ch[100];
int n=0;
int s=0;
while(scanf("%s",&ch)!=EOF)
{
s++;
}
printf("%d",s);
return 0;
}
while(scanf("%s",&ch)!=EOF)这段代码的意思是当当前输入缓存还有东西时就一直读取,直到输入缓存中的内容为空时停止,而scanf在读取到空格,换行符之类的东西时,就会停止读取,所以符合一个单词的定义,只要在while里定义一个观测值,最后输出它就行了。
#include<stdio.h>
#include<string.h>
int main()
{
char a[81];
gets(a);
int n=strlen(a),i;
for(i=n-1;i>=0;i--)
{
printf("%c",a[i]);
}
return 0;
}
运用gets函数,将语句存入数组中,再用strlen函数,算出字符长度,作为限制量,最后运用for函数倒序输出。