【发布时间】:2012-11-23 17:21:44
【问题描述】:
我是 C 的新手。 我有一串单词,例如一篇新闻报纸文章 我想将文章中的单词按字母顺序存储在不同的文件中 比如“我所看到的都是灵感,但我不想被淹没”。
现在,在上面的示例中,我想将所有以'a' 开头的单词存储在文件a.txt 中。同样以'b'开头的单词要存储在b.txt中
我正在使用下面的语法,但这不起作用
{
if(strcmp(wordcheck, worddict)==0)
fprintf(out_file1 ,"%c", wordcheck); //storing the value in a.txt
}
我还有一个问题,如果我获取一个包含单词列表的文本文件,并且我希望将此列表与许多列表(已经提供给程序)进行比较,这意味着输入列表中的任何单词是否匹配与任何来源列表中的单词我希望仅当在 list1.txt 中找到该单词时将该单词存储在文件 a.txt 中)。同样,如果在 list2.txt 中找到该单词,我希望将其存储在 b.txt 中。除此之外,我想在输出文件 a.txt 中显示文件 list1.txt 的路径。 喜欢 唱./dataset/dictionary/verb
我使用了下面的语法
while(dictcount >= 0)//reads dictionary word into array//
{
dictcount = 0; //searches through all of the listed data files
fscanf(fp1,"%s", worddict);
fscanf(fp2,"%s", worddict);
fscanf(fp3,"%s", worddict);
if(strcmp(wordcheck, worddict)==0)//compare strings//if the word in found in list misc.txt
{
fprintf(out_file1 ,"%c", wordcheck); //storing the value in output_misc.txt
if (getcwd(cwd, sizeof(cwd)) != NULL) {
//fprintf(out_file3, "%c\n", cwd); //stores the path of the folder containing the list in which the matched 'word' is found
return 0;
}
}
}
【问题讨论】: