formatted text from file.?

This is a discussion on formatted text from file.? within the C Programming forums, part of the General Programming Boards category; Can someone tell me something about reading text from a textfile (c-prog) I'm want to make a program, which can ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    64

    formatted text from file.?

    Can someone tell me something about reading text from a textfile (c-prog)
    I'm want to make a program, which can store info. in a file, and this info. will be kept in a file, so when I turn on the program again, so one don't have to write all the info. more times..Is like a database.
    fx. it can be as follows:
    Name: age Donation
    1. Morten Madsen 32 40.000 kr.
    2. Grethe Jacobsen 58 420.000 kr
    etc.

    Then you can call the date, with fx 1. then the name and age and donationsdate will be located into a struct, so I can use it on the screen
    ex.
    struct data
    {
    char name[30];
    int alder;
    float donation;
    }record;

    But how do i read the formatted text from the file, så I can split the textstringup into 3, so the can go into the struct on the right places.

    Does anybody know anything about this, i'm having trouble finding manuals about this.

    Regards

    !G!
    !G!

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Use fgets to read the entire line of a record and then use sscanf to break it up into individual pieces. Here's a page that explains exactly what you want.
    [shameless plug]
    http://www.flashdaddee.com/Tutorials/prelude1.htm
    [/shameless plug]

    -Prelude
    My best code is written with the delete key.

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Yes, there are a whole slew (sp?) of functions to work with and edit/save/manipulate files. Prelude gave a good link to a tutorial that was written by an excellent programmer ...
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 05:27 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 04:53 AM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 01:36 PM
  4. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21