I wrote this function to read a line from a file:
const char *readLine(FILE *file) {
if (file == NULL) {
printf(\"Error: file pointer is null.\"
readLine()
returns pointer to local variable, which causes undefined behaviour.
To get around you can:
readLine()
line
using malloc()
- in this case line
will be persistent