编写一个C语言的程序????

来源:百度知道 编辑:UC知道 时间:2024/05/21 12:12:31
输入一个英文语句(以句号结束),要求将句子中的单词分别打印出来

用循环做,谢谢

C程序,输入一个英文句子,以句号结束,回车之后输出句中的单词数量,单词之间以空格分隔

在WINDOWS+BCB2007以及SOLARIS+GCC中测试通过。

//---------------------------------------------------------------------------

#include <stdio.h>
#include <ctype.h>

int main(int argc, char* argv[])
{
int s=0;
char c;
while ((c=getchar())!='.')
if (isspace(c))
s++;
printf("%d\t words",++s);
return 0;
}
//---------------------------------------------------------------------------

#include "stdafx.h"
#include<iostream>
#include <sstream>
using namespace std;
#include <string>

int main(int argc, char* argv[])
{
string line;

getline(cin,line,'.'); // 从键盘输入一行英文语句
cout<<line<<endl;

string world;
for(istringstream istr(line); istr>> world;)
cout<<world<<endl; //输出