I'm writing this function which can read a file in the format of
1999 24324938
2000 59469955
2001 68478498
2002 73547547
2003 86796079
store each column in a separate array so I can use them later for some mathematical formula.
so far I've written this much, and dont know where to take it from here
int ReadFile(void)
{
FILE *fp; /* create a file pointer that will reference your text file*/
char buf[80]; /* what I read into*/
int n1, n2; /* reading two numbers */
char filename;
fp = fopen("input.txt", "r"); /* open up the file you're looking for*/
if (fp == NULL) /* problem opening the file*/
return(1); /*quit*/
while (fgets(buf, 80, fp) != NULL && !feof(fp)) /* keep reading till i reach the end*/
{
sscanf(buf, "%d %d", &n1, &n2); /* buf is one line of the input file which contained two columns, so read in each var*/
printf("n1 = %d n2 = %d\n", n1, n2); /* print the results to stdout*/
}
fclose(fp);
}
Any help would be appreciated.