一道挺简单的c语言的题

来源:百度知道 编辑:UC知道 时间:2024/05/21 06:55:18
拜托了,写的详细点啊。
写一个程序读一个文本文件 此程序必须统计行数,单词数,字符数(含空格),字符数(不含空格),段落数。程序须类似于微软的WORD中字数统计功能。结果须写入另外一个文件中。
一个例如下:
Please enter the file name: words.txt
Processing….
The results can be found at words.rpt
这个文件中要包括这篇文章,
In artificial intelligence ,an embodied agent is an intelligent agent , that interacts with the environment through a physical body within that environment. Agents that are represented graphically with a body, for example a human or a cartoon animal, are also called embodied agents, although they have only virtual, not physical, embodiment. A branch of artificial intelligence focuses on empowering such agents to interact autonomously with human beings , and the environment.

Mobile robots , are one example of physically embodied agents; Ananova , and Microsoft Agent ,are examples of graphically embodied agents. Embodied Conversational agents are embodied agents (usually with a graphical front-end as opposed to a robotic body) that ar

你的输入文件不要用unicode,要用ASCII
分行用 '\n'
分段用 两个 '\n'
标点符号与最近的词中间不要有空白,

例如 [intelligence ,] should be [intelligence,]
否则统计成两个词。

#include <stdio.h>

FILE *fin, *fout;
void main()
{
char namein[64],nameout[64]="words.rpt";
int ci,sp=0,zi=0,d=1,h=1,tmp,tmp2=0;
char st[30];

printf("Please enter the file name: words.txt \n");
fscanf(stdin,"%s",&namein);
printf("Processing…. \n");

if ( ( fin = fopen(namein, "r") ) == NULL ) {
fprintf(stderr,"can not open file %s\n",namein);
exit (-1); };

if ( ( fout = fopen(nameout, "w") ) == NULL ) {
fprintf(stderr,"can not open file %s\n",nameout);
exit (-1); };

ci = 0;
while( 1==1){
if (fscanf(fin,"%s",&st) == EOF) break;
ci=ci+1;
};