繁体   English   中英

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

[英]Using fscanf to read text then printing that text into a file using fprintf

因此,我程序的目标是从文件中读取一些文本,将其编码为另一个文本文件,然后对该单词的内部字母进行加扰,因此我需要将每个单词分别编码,而不是在字符串中编码,因此我最终可以稍后再做。 到目前为止,我有:

#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文本文件中,我只是将所有内容打印在一行上。 请帮助?

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

如果您希望每个单词都换行

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM