早教吧 育儿知识 作业答案 考试题库 百科 知识分享

编写一个程序,它使用一个char数组和循环来每次读取一个单词,知道用户输入done为止.随后程序指出输入了多少单词,不包括done,下面是运行情况:Enterwords(typedonetostop)Todayisasunnydaydone,isn't

题目详情
编写一个程序,它使用一个char数组和循环来每次读取一个单词,知道用户输入done为止.随后程序指出输入 了多少单词,不包括done,下面是运行情况:
Enter words(type done to stop)
Today is a sunny day done,isn't it?
You entered a total of 5 words
您应该在程序中包含头文件cstring,并使用strcmp()来进行比较测试
▼优质解答
答案和解析
#include
void main()
{
int i,words=0;
char a[99],str[99];
for(i=0;;i++)
{
a[i]=cin.get();
str[i]=a[i];
if(a[i]==' ') words++;
if(a[i]=='e'&&a[i-1]=='n'&&a[i-2]=='o'&&a[i-3]=='d'){str[i-3]='\0';break;}
}
cout<<"You entered atotal of "<}
看了 编写一个程序,它使用一个ch...的网友还看了以下: