// class AccountBase -- this can be used too...
struct AccountBase
{
public:
string firstname;
string lastname;
double balance;
AccountBase *NextAccount; // the pointer for the linked list.
};
I have seen this problem a dozen times on this board since I have been participating on it. this is the base structure of most Linked Lists. How you approach this from here is choices you need to make and that is program design.
Are we doing c++ or c? They are two different approaches and this is a c++ board.
I didn't expect to see the c style read of a file for a c++ program.
Do you know the concepts of a Linked List? Do you realize you are doing dynamic Allocations, and would have different language syntax to handle that read?
This program is in C language. I know the concept behind linked list. so this is what I did so far with the problem am having above and i still get an error
what I see in the code pieces you have supplied is the structure that looks like it is defined correctly.
1 2
struct account people [MAXCHAR]; // this doesn't make any since, do we want a linked list or array?
account people[MaxChar]; // this would set up an array of Accounts.
A linked list would track the Head of the list, like:
1 2 3 4 5 6 7 8 9 10
// this indicates I have a empty list, no elements.
account *HeadAccount = NULL; // I don't remember if this is legal in c99....
// creating the head element would look like, this is the dynamic allocation
// I would expect something similar for every iteration of account in the file I read. But it would be on the next pointer....
HeadAccount = malloc(sizeof(account));
//accessing the head account would look like
//it would look similar for each iteration of the file but doing it on a working pointer.
fscanf(file,"%s %s %lf \n", HeadAccount->last, HeadAccount->first, HeadAccount->balance);