» 首页 » 电脑_数码 » 编程 » 紧急!!!编写程序:输入一行字符,统计其有多少个单词,单词...

紧急!!!编写程序:输入一行字符,统计其有多少个单词,单词...

帮帮忙,由于一开始没认真听过课,所以要考试了,就不会编了,好心人帮帮我吧.这是个C语言的编写程序.因为下周5要考试了,所以很急,因此我会把我所有的分数都贡献


#include<stdio.h>
main()
{char c;
int word=0,speac=0;
printf("请输入一行字符:\n");
while((c=getchar())!='\n')
{if(c>='a'&&c<='z'||c>='A'&&c<='Z')
word=1+speac;
else if(c==' ')
speac++;
}
printf("单词=%d,空格数=%d\n",word,speac);
}

#include<stdio.h>
main()
{char c;
int word=0,speac=0;
printf("请输入一行字符:\n");
while((c=getchar())!='\n')
{if(c>='a'&&c<='z'||c>='A'&&c<='Z')
word=1+speac;
else if(c==' ')
speac++;
}
printf("单词=%d,空格数=%d\n",word,speac);
}

楼主是来转移积分的吧。我看你连什么是单词都没搞清楚。
#include <stdio.h>
#include <ctype.h>

int
countWords(void)
{
char c;
int i, state; // state of 1 in a word, 0 out of a word; i as counter

// get input from stdin, press Ctrl+D to send EOF in *nix, Ctrl+Z in M$ Windows
for (i = 0, state = 0; (c=getchar()) != EOF; state = isspace(c) ? 0 : (!state ? (++i,1) : state)); // increament i at the start of a word
return i;
}

int
main(void)
{
printf("%d\n", countWords());
return 0;
}

 相关问题
·紧急!!!编写程序:输入一行字符,统计其有多少个单词,单词...
·matlab对一维数组进行量化和归一化
·VFP高手帮忙蛤~~
·关于数据库:临时关系的名词解释
·那位任兄能帮我看一下下面的程序那里不对?
·加工中心接收nc程序步骤以及一些小问题/CNC问题/fanuc oi...
·asp.net如何取得存储过程的output,请高手指点
·请帮忙看下这个select语句应该怎么写?
·ASP如何调用ACCESS数据库二进制图片
·Set myobj=server.CreateObject(\"myobj.function\")
·用“茫然若失,魂不守舍,付诸东流,似曾相识”写一段话
·XMLHTTP 错误问题 高手进
·将二进制数1010001101转换成八进制数。
·MSSQL数据导入问题,高手请进
·程序分析题!! 有高手帮做一下的啊!!

 《紧急!!!编写程序:输入一行字符,统计其有多少个单词,单词...》答案收集时间:2008-06-14 14:47:14



©2007 电脑技术问答录