visual c++ - Using fopen_s in C -
i have problem programming in c, fopen in visual studio. read fopen_s function , added following line project, still doesn't work.
_crt_secure_no_warnings so tried using fopen_s in way:
file *fp; errno_t err; if ((err = fopen_s(&fp, "c:/file.txt", "rt")) != 0) printf("file not opened\n"); else fprintf(fp, "date: %s, time: %s, score: %i \n", __date__, __time__, score); fclose(fp); it's still crashing. what's wrong?
you use fclose invalid fp value, if opening failed. add {} around else branch, @ least.
many developers think idea use braces everywhere, 1 statement inside them. it's easy make mistake if don't, experienced developers. put them around then branch too.
Comments
Post a Comment