请告诉我编这个程序要解决的关键问题所在(C++)

来源:百度知道 编辑:UC知道 时间:2024/06/05 10:28:11
统计文本文件中单词的个数,要求统计结果输入另外一个文件中,源文件和结果文件名均由命令行参数指定。
我想知道要编出这个程序需要解决什么关键问题,,比如如何判断一个单词已经完结等,还有“源文件和结果文件名均由命令行参数指定”是什么意思……
请告诉我要点,程序我会试着自己编,谢谢!
首先谢谢moxianfeng和风似刀的回答!我们要求的是英文文本,按照空格分词我也编出了程序,后来我发现我们似乎没有学过命令行参数的问题,所以连“cp srcfile dstfile”是什么意思我都不知道啊……风似刀的程序我也不太看得懂……
我编的程序如下:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <fstream.h>
#include <iostream.h>
#include <stdlib.h>//

int main()
{
char str[80];
int i = 0, n = 0,m = 0;
ifstream in("fl.dat");
if(!in)
{cerr<<"open error!"<<endl;
exit(1);
}
in.getline (str,80);

for( i=0; str[i]; i++)
{
if((str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
{n++;}

if(str[i]==' '||str[i]=='\0'||str[i]==','||str[i]

如 moxianfeng 所言,中文文法的处理会让你感到掐死你的温柔,如果是英文的话就比较单纯,空白或标点间隔的就是一个单词,可以一次读入文件的一段然后反复调用

int main(int argc, char *argv[0]) {
以cp srcfile dstfile 为例,srcfile就是argv[1],dstfile就是argv[2]。

char *tmp;
const char *DELIMITER = " \n\t.,标点之类";
unsinged int word_count = 0;
.
.
打开输入文件fopen(argv[1], "rb");

char *file_block = fread(从文件反复读取一块);
.
.
for (tmp=file_block; ; tmp=NULL) {
char *token = strtok(tmp, DELIMITER);
if (! token)
break;
++word_count;
}
重复以上操作直至输入文件读取完毕,然后fwrite将word_count写入输出文件argv[2]。

大体如此。
########################################################
抱歉抱歉,没注意到你说的是C++,如果是C++的话大体如下

#include <iostream>
#include <iterator>
#include <algorithm>
#include <fstream>
#include <vector>
#include <functional>

int