使用fscanf读取文本,然后使用fprintf将该文本打印到文件中

时间:2016-11-22 00:28:59

标签: c

所以我的程序的目标是从文件中读取一些文本,将其编码到另一个文本文件中,然后将单词的内部字母加扰,所以我需要单独编码每个单词,而不是字符串,以便我最终能够在以后执行此操作。到目前为止我有:

#define INPUT_FILENAME    ("A6P1_2016_TestingSherlock.txt")
#define OUTPUT_FILENAME     ("EncodeMe.txt")

void process_file(FILE* ifp, FILE* ofp) {
printf("Begin file processing\n");
char word[100];
while(fscanf(ifp, "%s", word) != EOF){
    fprintf(ofp, "%s ", word);
}

printf("End file processing\n");
}

我从输入文件中获取的文本如下

Project Gutenberg The Adventures of Sherlock Holmes, by Arthur Conan Doyle
This eBook is for the use of anyone anywhere at no cost and with
almost no restrictions whatsoever.  You may copy it, give it away or
re-use it under the terms of the Project Gutenberg License included
with this eBook or online at www.gutenberg.net

在EncodeMe文本文件中,我只需将所有内容打印在一行上。请帮忙吗?

1 个答案:

答案 0 :(得分:0)

fprintf(ofp, "%s\n", word);

如果你想在新行上的每个单词

相关问题