Link to home
Start Free TrialLog in
Avatar of reesee324
reesee324

asked on

How do I read information from a text file and store it into an array in C?

I don't understand how to load the file and then read the info and store it in an array. This is what the file looks like:
125
LIPSO FACTO
SC
A
118.030000
61
193
TAMMALIZATION CO.
SC
B
3728.000000
23
237
MORE MATZOES
TN
A
846.290000
12

And each line should consist of a cust id, customer name, state, discount code, balance due, and outstanding orders. How would I go about storing each of the lines into each of the seperate arrays?
Avatar of phoffric
phoffric

Your question is really a request for us to do this assignment for you, and this is against EE academic policy. You may get a response if you write code that has a problem (e.g., doesn't compile) and we'll help you compile it. Then you can ask a different question if you don't get the desired results, and we can try to point out a problem in your program.
Avatar of reesee324

ASKER

Well the problem is I don't even understand how to start writing the code to even begin to make it work. I understand how to open the file and then you would use a while (!feof(fp)). This is my first year using c but I didn't know if you could do cust_id = get_int(fp) and so on and so forth for each type. If I had any idea of how to write it then I would.
SOLUTION
Avatar of Kendor
Kendor
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi reesee,

Well, there are several ways to do this. Try to do some research on getline(), getchar() function, fstream, ifstream variables.

I can say start from small code snippets make them work. You can progress step by step. First write a program to open a file and read the characters or lines from it. Then write a program to insert characters or strings into array. Now think of using both programs together.

Thank you,
Chaitu
Ok thanks guys!
Please accept a solution and award points if you are satisfied reesee
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> Try to do some research on getline(), getchar() function, fstream, ifstream variables.
    These are good suggestions if you wish to write C++ code. If so, you should in the future select the C++ zone.

From all the above suggestions, you should try putting the pieces together by building a little at a time, getting just a little to work (like read a line in, for example). Then add on another little piece of the puzzle.
Actually you should give points to the post that answered your question. Not as you did.
Ok thanks! I appreciate the help and I'm still trying to get used to this points system. I just registered with ya'll so I'm still trying to get the hang of things!