i am trying to read a file using fgets.
the point is that i want to read a line in a csv file than splitting the columns of this file into arrays.
the code i am using is the following
CODE
#include <stdio.h>
#include <string.h>
#define max_r 762
#define max_c 7
typedef struct{
int day;
char month[3];
int year;
}DATE;
typedef struct {
char StockName[20];
DATE date;
float ClosingPrice;
}BHP;
int main(void)
{
FILE* infile;
int i,j;
/* BHP stock[max_r][max_c];*/
char buffer[762];
char delims[] = ",";
char *result = NULL;
infile=fopen("bhp.csv","r");
if (infile == NULL)
printf("Error opening the file!!\n!");
/* Read the file*/
for(i=0;i<762;++i)
for(j=0;j<7;++j)
fgets(buffer,max_r,infile);
puts(buffer);
/* spliting the columns*/
result = strtok( buffer, delims );
while( result != NULL ) {
printf( "result is \"%s\"\n", result );
result = strtok( NULL, delims );
}
}
my problem is that i am only reading the first line of the file
but i want to read all of it.
can anyone help?