Reading word by word from a file,HOW???????

Discussion in 'C' started by jose_peeterson, Jun 14, 2011.

  1. jose_peeterson

    jose_peeterson New Member

    Joined:
    May 19, 2011
    Messages:
    56
    Likes Received:
    1
    Trophy Points:
    0
    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
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     
  3. jose_peeterson

    jose_peeterson New Member

    Joined:
    May 19, 2011
    Messages:
    56
    Likes Received:
    1
    Trophy Points:
    0
    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); then after storing in this array. put in a loop and check
    if(array == " ") // 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
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice