Tyler Tootle
Tyler Tootle

Reputation: 1

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?

Upvotes: 0

Views: 222

Answers (1)

pm100
pm100

Reputation: 50200

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

if you want each word on a new line

Upvotes: 0

Related Questions