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

输入一个英文语句(以句号结束),要求将句子中的单词分别打印出来

用循环做,谢谢

第1个回答  2008-02-24
#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; //输出每个单词
}

这个程序在vc++上通过了,你输入:
we are the best.就会正常运行。
别忘了给点分
第2个回答  2008-02-24
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;
}
//---------------------------------------------------------------------------本回答被提问者采纳
第3个回答  2008-02-24
抓分隔符

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网