Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Reading word by word from a file,HOW??????? (http://www.go4expert.com/forums/reading-word-word-filehow-t26054/)

jose_peeterson 14Jun2011 13:39

Reading word by word from a file,HOW???????
 
According
to a
research at Cambridge
University it does not
matter in what order the
letters in a word are the
only important thing is that the first
and last letter be in the right place.

hello experts,

the above is a text file content. i want to read it word by word then MODIFY each word and then use strcat() to form back sentences with one space between words.i tried to use fscanf() i could only read the first word. i want read a word then modify it then concatenate to form back sentences e.g.

Aordinccg
to a rrceseah at Cridgambe
Utniversiy it deos not
meattr in waht oerdr
the leretts in a wrod are the
olny iportanmt tinhg is that the fsirt
and lsat ltteer be in the rghit pclae

I KNOW THE MODIFICATION JUST HELP ME READ WORD BY WORD ALL THE WORDS, thanks

xpi0t0s 16Jun2011 03:49

Re: Reading word by word from a file,HOW???????
 
One way is to read character by character, placing every character that is part of a word into a temp buffer, then when you hit a character that isn't a word-character (space, new line, comma etc) process the word, then skip over all non-word characters until you hit a word-character again, then initialise the string with that character, and loop until you hit EOF.

jose_peeterson 17Jun2011 19:10

Re: Reading word by word from a file,HOW???????
 
first Thanks for your reply. i thought my thread was lost in the sea of posts.
so you mean char array[1000];
to read as fsanf(file pointer,"%c",&array[i]); then after storing in this array. put in a loop and check
if(array[i] == " ") // look for space create a loop within and go from 0 to i (in this case). change to another array then modify.
ok thanks i will try and let you know


All times are GMT +5.5. The time now is 10:40.