Inside main, i have the following procedure to get numbers from a file:
FILE *f = fopen("numbers.txt", "r");
if(f != NULL) {
char line[BUFFER_SIZE];
while(fgets(line, sizeof(line), f) != NULL) {
char *start = line;
int field;
int n;
while(sscanf(start, "%d", &field, &n) == 1) {
printf("%d \n", field);
start += n;
}
}
fclose(f);
}
If I add an integer array above this, e.g. int num[100], I get an access violation.
It seems that this somehow causes problem with the file-reading, but I can't see how at the moment.
sizeof(line)is guaranteed to be the same asBUFFER_SIZE, not 4 or 8. Where did "4 or 8" come from? Arrays don't decay to pointers undersizeof."%d"--->"%d%n"