if i have a file.txt with comma separated value and i need to access the 10th and 15th columns ofthis file and save each one in an array
i tried this code (which was attached in the site) but it didn't work it always print the 3rd column of the file and i still don't know why!!
Code:
#include <stdio.h>
#include <stdlib.h>
#define FIRST_LINE 0
#define LAST_LINE 10
int main() {
char buf[512];
int line_count = 0;
FILE *file = fopen("min_chest.txt", "r");
while (fgets(buf, sizeof buf, file) != NULL) {
double value;
if (sscanf(buf, "%*lf,%*lf,%lf,*%lf,%lf", &value) != 1) {
fprintf(stderr, "sscanf failed.\n");
exit(EXIT_FAILURE);
}
printf("%f\n", value);
if (line_count++ >= 10)
break;
}
fclose(file);
return 0;
}
it was refreenced here
Reading values from a csv file in c into an array
why it always prints the 3rd column ?
and if i need to know the size of the file automatically how to know that ??
any advice of how to get it well ?