Originally Posted by
johnhuge
Thanks for the reply. If you could answer a quick question. How would i read the input file to the following and store it to the array first[], last[], balance and allocate enough memory to hold the info. in from the input file.
How many people you got on that list?
Arrays are only good if you have a known, small number of records to work with... up to say, 100 or so.
Linked lists are good when you have a small to medium but unknown number of records ... again up to maybe 200 or so.
What you really need for any kind of reasonable implementation is random access filing... handle tens of thousands of records with a single struct.
Plus, your struct is broken to begin with...
Code:
struct name{
char *first[];
char *last[];
int *balance[];
}
Means you have to allocate memory for every first and last name... which can be a major source of errors in linked lists and won't work at all in random access files... You probably also want to store an account number so...
Redo your struct like this...
Code:
struct name{
char first[32];
char last[32];
unsigned int account;
int balance; }
Now your structure has built in storage for the strings, an account number, and the balance value. Because of the last bit ambiguity problem with floats and doubles, it is often better to work with integers for financial records, and do all your "accounting" in pennies...