Originally Posted by
itCbitC
I'm not convinced he needs a collection of records at all.
Originally Posted by
wollek
Reading the data in one at a time would mean that sorting the data and working with it would need a lot of disk access which would slow down the program runtime way to much.
Well don't assume; know. Usually you would code first, and then measure the actual run time performance using a program called a profiler.
Nevertheless, that's no justification for not processing one record at a time. You just haven't thought the algorithm through:
Code:
#include <stdio.h>
struct record {
int one;
};
int main()
{
struct record weather;
/** make a file **/
FILE * fp;
int i;
fp = fopen("test.txt", "w");
for(i = 1; i <= 10; i++) {
weather.one = i;
fprintf(fp, "%d\n", weather.one);
}
fclose(fp);
/** read the file **/
fp = fopen("test.txt", "r");
while(1 == fscanf(fp, "%d", &weather.one)) {
/** process **/
printf("weather.one == %d\n", weather.one);
}
fclose(fp);
remove("test.txt"); /** removing the file from my HD **/
return 0;
}
That should be enough, based on what I actually know about your real goals.