Thread: Hi Help with reading a file and string modification

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    39

    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

    s=abcddddddeeeffffff
    t=ddddrrrffffabcgggggshhhhh
    w=gggdjjuuuuabciugdiasugdaoiugsd

    etc

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

    s=zddddddeeeffffff
    t=ddddrrrffffzgggggshhhhh
    w=gggdjjuuuuziugdiasugdaoiugsd
    z=abc

    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
    Posts
    2,158
    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?

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    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
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    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)

    str1=abcddddddeeeffffff
    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