简体   繁体   中英

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

So the goal for my program is to read some text from a file, have it encoded into another text file, and then have the inside letters of the word scrambled, so i need each word encoded separately, as opposed to in a string, so that i can end up being able to do this later. So far i have:

#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");
}

The text that i'm taking from the Input file is as follows

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

And in the EncodeMe text file, i just get everything printed on one line. Help please?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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