2016-11-22 4 views
0

私のプログラムの目的は、ファイルからテキストを読み込んで別のテキストファイルにエンコードし、その中に文字をスクランブルので、文字列ではなく、別々にエンコードされた各単語が必要なので、後でこれを行うことができます。これまでのところ、私が持っている:fscanfを使ってテキストを読む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テキストファイル内に以下のように、私はちょうど1行に印刷されたすべてのものを得ることです。助けてください?

+0

は一度に行全体を読んで、そしてラインから個々の単語を取得するために 'strtok'を使用するために、' fgets'を使用したい場合。 – user3386109

+0

@ user3121023おっと、私は文字列の代わりに、別々にエンコードされた各単語が必要だと言いました。以前は正確なコードを使用していましたが、単語を簡単に編集することはできません –

答えて

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

新しいライン上の各単語

+0

しかし、私はそれ自身の行のすべてを望んでいません。 –

+0

その後、一度に行全体を読み、それを印刷してから単語に切り詰めます。行を読み込む方法をheresします。http://stackoverflow.com/questions/2372813/reading-one-line-at-a-time-in-c – pm100

関連する問題