1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| static int field_count ( char* filename)
{
printf("Beginning of field_count() for the file : %s \n", filename);
int nb_f = 0;
int nb_fields ;
//int nb_lignes;
FILE* file_in;
char c={0};
file_in = fopen(filename, "r");
if (file_in == NULL)
{
printf("ERROR: Impossible to open the temporary file %s in reading mode \n", filename );
printf("ERROR CODE IS %d \n", errno);
exit (-1);
return(0);
}
/* nb_fields contain the number of fields in a line */
while ((c!= EOF) && (c !='\n'))
{
c = getc(file_in);
if (c ==',')
{
nb_f++;
printf("the counter reached the value :%d \n",nb_f);
}
}
printf("we finished the count, we will close the file");
fclose (file_in);
nb_fields = nb_f;
printf("the number of fields is: %s \n",nb_fields);
printf("end of field_count() \n \n ");
return (nb_fields);
} |
Partager