Hi i had a sample code for reading and writing on a txt file but visual studio wont read the code and keep crashing and giving same error 0x80070002 (error happens in bot "w" and "r" formats) here is the code
#include <stdio.h>
#include <stdlib.h>
int main(void) {
FILE* fp;
if ((fp = fopen("C:\Users\39351\source\repos\exercise\prova.txt", "r")) == NULL)
exit(1);
else {
int c;
while ((c = fgetc(fp)) != EOF) putchar(c);
fclose(fp);
}
}
no matter the code when i use the fopen command even fopen_s it gives this error can someone help?
The backslash (\) character introduces an escape sequence in C string literals, so it's trying to process the \U, \3, \s, \r, \e, and \p as escape sequences. For example, \r translates to a carriage return character. To fix this you need to double up the backslash characters:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
FILE* fp;
if ((fp = fopen("C:\\Users\\39351\\source\\repos\\exercise\\prova.txt", "r")) == NULL)
exit(1);
else {
int c;
while ((c = fgetc(fp)) != EOF) putchar(c);
fclose(fp);
}
}
try to use '/' istead '\'
you can change the location of the file, it may be a permission failure
User contributions licensed under CC BY-SA 3.0