Thread: Hi Help with reading a file and string modification

  1. #1
    Registered User
    Join Date
    Jun 2009

    Question Hi Help with reading a file and string modification

    Hi All,

    I have a particular problem on hand and was thinking what would be a good way to solve the same.

    I have a text file with a lot of lines,say



    I need to read the file, and get the output such that:


    etc, the number of such words that i may need to replace are many.

    what would be the best way to solve the problem,

    Should I read the file line by line keep on replcing all the occurences of the abc to z and at the end of the file add the formula z=abc????

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Is this an assignment?

    There's more than one way of doing this. So why not just try the idea you presented and then ask for help when you have trouble?
    I just want to use my computer in a productive manner, not learn how to use it. Elysia
    A year spent in artificial intelligence is enough to make one believe in God. Alan Jay Perlis

  3. #3
    Registered User
    Join Date
    Sep 2008
    Toronto, Canada
    Is the z=abc formula included in the file as the last line? If so, I'd read the entire file down to that line, save the "from" and "to" values someplace, then rewind the file and process line by line.

  4. #4
    Join Date
    Oct 2008
    so you want to replace "abc" by "z" in each string.
    i would build a char* function which returns the end of "abc" in the string (it whould return to str3)

    and then i would build a string str2 which has "z"
    and the i will do strtoc (str2,str3);

    thats when you have a case when abc is in the start
    then same principle you can do if it ends by abc.

    but when abc in the middle
    thats harder you whould need to do 2 strcat's

    good luck

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM