Soldato
- Joined
- 5 Aug 2006
- Posts
- 11,419
- Location
- Derbyshire
I am learning to write to files in c programming. I have a program that reads a file and can display that file on the screen (it is a little tricky as the file has table-style data in it, so there is an array of structures, with a structure holding a line of data).
If I have this (this is not what I have, but something similar as I want to try myself).
How would I write this to a .dat file??
I think I need a for loop with a counter to increment a counter, so it writes a line, increments, writes next line, increments etc etc until the end of file is found.
This is just a tutorial but I have spent hours trying to find the right approach. It is really bugging me!
Many thanks
If I have this (this is not what I have, but something similar as I want to try myself).
Code:
struct people
{
int age;
double weight, height;
};
struct people people_array[100];
I think I need a for loop with a counter to increment a counter, so it writes a line, increments, writes next line, increments etc etc until the end of file is found.
This is just a tutorial but I have spent hours trying to find the right approach. It is really bugging me!
Many thanks

Last edited: