Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when trying to write file fprintf does not work

Tags:

c

io

I am just trying to open and write something in file but when visual studio tries to execute fprintf program crashes here is my code

#include<stdlib.h>
int main()
{
    FILE* fPointer;
    fPointer = fopen_s(&fPointer,"‪C:\\asd.txt","w");
    fprintf(fPointer, "If ı can read this then ı can create for loop");
    fclose(fPointer);
    return 0;
}

here is the error message : Access violation writing location 0x0000003A.

like image 324
Kaan Binen Avatar asked Oct 28 '25 22:10

Kaan Binen


1 Answers

fopen_s return value is an error number and you overwrite your file pointer with that which you should not do.

like image 143
Eraklon Avatar answered Oct 31 '25 14:10

Eraklon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!