View Single Post
Old 05-02-2004, 09:30 PM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
Re: Reading in a file

Quote:
Originally posted by jello
I'm working on a program in which I need to read into a list, from text file: a task name, it's due time, the hours needed to complete the task, and the number of points the task is worth.

I'm using a simple structure:
Code:
struct Task
{
   string name;
   int dueTime;
   int hoursNeededToComplete;
   int nmbrPoints;
};
Since you're using string you could be coding in C++, here I would just overload the >> operator, to put everything into your struct, but to make that work you would have to rename your struct to class.
however
Since it is a struct you're defining here, then it indicates you're using strict ansi C, then I would sugest you to look at fopen(), fscanf() and fclose()

Quote:

The format of the text file is as follows:

name dueTime hoursNeededToComplete nmbrPoints
name dueTime hoursNeededToComplete nmbrPoints
name dueTime hoursNeededToComplete nmbrPoints

etc.
Good format, are those tabs between the columns ? If so, fscanf() might be what you are looking for...

Altho a wee bit of code to give anyone an idear where your thoughts are would help some more.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote