I've run into stuff like this before but usually just when dealing with stdout
.
#define LOG 1
static void logoutput(char *info) {
FILE *dbg;
dbg = fopen(LOGFILE, "a+");
if(dbg != NULL) {
fprintf(dbg, "Mix%d: %s\n", MIXNUM, info);
fclose(dbg);
}
else printf("Error writing to log file.\n");
return;
}
if (data[0] != NULL) {
if(LOG) logoutput("WARNING, something bad happened on port 1!");
exit(1); //Adding a sleep(1); before this didn't help.
}
The problem I'm having is that when data[x] != NULL
, the program exits immediately and never logs anything.
I tried adding a sleep(1);
but that didn't do the trick. I searched around but couldn't come up with the right terms. What's the best way to handle this?