Thread: reding file and changing parts

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    1

    reding file and changing parts

    hallo i am new in here, i have a homework for to morning. and i am greatly stuck
    i have to make a program that reads a file with this information.

    Susanne;Hansen;2010e
    Christian;Hansen;2010e
    Pernille;Hansen;2010a
    Peter;Jensen;2010b
    Hans;Thomsen;2010b
    Pia;Petersen;2010a
    Bodil;Lorentzen;2010e
    Henrik;Steen;2010b
    Sten;Hansson;2010e

    and should make it to look like this

    SH1;SH1DTU;2010e;Susanne;Hansen
    CH2;CH2DTU;2010e;Christian;Hansen
    PH3;PH3DTU;2010a;Pernille;Hansen
    PJ4;PJ4DTU;2010b;Peter;Jensen
    HT5;HT5DTU;2010b;Hans;Thomsen
    PP6;PP6DTU;2010a;Pia;Petersen
    BL7;BL7DTU;2010e;Bodil;Lorentzen
    HS8;HS8DTU;2010b;Henrik;Steen
    SH9;SH9DTU;2010e;Sten;Hansson

    my question is how do i make it to stop reading at the ; points and storing the information to later use.

    Ps. sorry for my bad english.
    Daniel V.

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    Read one line at a time and use strchr to locate the desired delimiter character. This means you will need pointers to the beginning of the string and to every occurrence of the delimiter character. Extracting a substring and then writing it back to the file can be done in a number of different ways depending on how efficient you want to be. I suggest you google for "extract substring c" or similar for different ways of doing it.

    strchr - C++ Reference

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you help me about tolower() in file
    By nctar in forum C Programming
    Replies: 7
    Last Post: 05-12-2010, 10:04 AM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  3. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  4. Deleting / Changing a record in a text file
    By clearrtc in forum C Programming
    Replies: 9
    Last Post: 08-21-2006, 12:09 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM