I have this very simple C code, which is supposed to create a .txt file and write to it.
#include <stdio.h>
int main() {
FILE* f;
if ((f = fopen("asdTEST.txt", "w")) == NULL) {
printf("Failed to open.\n");
return 1;
}
else {
fprintf(f, "Hello\n");
fclose(f);
printf("Success!\n");
}
return 0;
}
My problem is, it doesn't do it, when I compile it in Visual Studio 2019. What's strange - it does work in one project, but if I create a new one and copy-paste the code there, it won't create the file. However, it will end with code 0 as if it was successfull. If I run the compiled binary as an Administrator, it works just fine.
(in the one successful project it creates the .txt file in the directory, where the source code .c is located, and that's what I want it to do)
My question is - why the same code works in one VS project and not in other (new) ones ? What can I do to fix this ?
Thank you!