I have a simple question about using fgets() with char* string.
....
char *temp;
FILE fp=fopen("test.txt", "r");
fgets(temp, 500, fp);
printf("%s", temp);
....
This code didn't work well.
But after I modified char *temp
to char temp[100];
, the code worked well as I intended.
What is the difference between those two?
When I googled it, some said that memory must be allocated to char *
using malloc()...
But I couldn't understand it.