I can’t open a file in C, even though the file exists and isn’t used by any application. Can someone tell me what is causing this problem?
int main()
{
FILE* oud;
unsigned size;
unsigned* bytes;
char path[] = "C:\\Users\\Ruben\\Documents\\test.txt";
errno_t error;
if ((error = fopen_s(&oud, path, "rb" )) == NULL)
{
perror(NULL);
getchar();
return -1;
}
fclose(oud);
getchar();
return 0;
}
}
The output is: “No error”.
fopen_s()returns0on success, notNULLon failure:The
NULLmacro is#defined to0(probably) which means if the file is opened theif()in the posted code is:which is obviously true. Change to: