I was playing around a little bit and noticed that the length of my input was longer than the allocated bits of my char*. I then choose to allocate even less memory and eventually set it to 0.
I have not tried, but I would assume that this is also the case for other stdio input functions.
int main(){
FILE *file;
file = fopen("../input.txt", "r");
if(file == NULL){
printf("Error with reading file");
return 0;
}
int *bounds = (int*) malloc(0);
char c, *token = (char*) malloc(0);
while(fscanf(file, "%i-%i %[^\n]", bounds, bounds + 1, token) != EOF){
printf("%i-%i %s\n", *bounds, *(bounds + 1), token);
}
}
Is there any specific reason for this behavior, especially that it does not yield an error? It would be lovely to get some info on this. Thank you in advance!