Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c language : fwrite doesnt do anything

Tags:

c

fwrite

{
    FILE* f1 = fopen("C:\\num1.bin", "wb+");//it will create a new file 
    int A[] = { 1,3,6,28 }; //int arr
    fwrite(A, sizeof(A), 1, f1); //should insert the A array to the file
}

I do see the file but even after the fwrite, the file remains empty (0 bytes), does anyone know why?

like image 765
Itsik Elia Avatar asked Nov 25 '25 00:11

Itsik Elia


1 Answers

You need to close the file with fclose

Otherwise the write buffer will not (necessarily) force the file contents to be written to disk

like image 131
Grantly Avatar answered Nov 27 '25 14:11

Grantly



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!