私は単語ごとに読もうとしていますが、以下は私が採用したロジックです。これは、現在のファイルの最後の単語と次の新しい行の最初の単語を格納する行の最後の単語に到達する場合を除いて、単語をうまく読み取ります。誰かがこれを機能させる方法を教えてもらえますか?
int c;
int i =0;
char line[1000]
do{
c = fgetc(fp);
if( c != ' '){
printf("%c", c);
line[i++] = c;
}else if((c == '\n')){
//this is where It should do nothing
}else{
line[i] = '\0';
printf("\\0 reached\n");//meaning end of one word has been reached
strcpy(wordArr[counter++].word, line);//copy that word that's in line[xxx] to the struct's .word Char array
i=0;//reset the line's counter
}//if loop end
} while(c != EOF);//do-while end
fp
ファイルポインタです。
HI BABY TYPE MAYBE
TODAY HELLO CAR
HELLO ZEBRA LION DON
TYPE BABY
私は得ています(引用符なし)
"HI"
"BABY"
"TYPE"
"MAYBE
TODAY"