Using fgets() with char* type

后端 未结 3 936
傲寒
傲寒 2021-01-12 15:17

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\", te         


        
3条回答
  •  误落风尘
    2021-01-12 16:08

    char *temp is uninitialized, that is, it isn't pointing to valid memory. Either make it an array (char temp[]) or use malloc to assign memory for it.

提交回复
热议问题