How to write numbers to binary file in C

1 Answer

0 votes
#include <stdio.h>
 
int main(int argc, char **argv) 
{ 
    FILE *f;

    f = fopen("d:\\data.bin", "wb");
    if (!f)
    {
        printf("Unable to open d:\\data.bin");
        return 1;
    }
    for (int i = 1; i <= 10; i++)
			fwrite(&i, sizeof(int), 1, f);
    
    fclose(f);
     
    return(0);
}
 
/*
run:
 
data.bin
--------
characters with no meaning to you                      	   
                        	 

*/

 



answered Jul 24, 2015 by avibootz

Related questions

2 answers 251 views
1 answer 280 views
1 answer 234 views
1 answer 172 views
2 answers 227 views
...