How to write a string to binary file in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
 
int main(void)
{
    FILE *fp;
    char s[15] = "C Programming";

    fp = fopen("d:\\data.bin","wb");
    if (!fp) {fputs("File open error",stderr); return 1;}

    fwrite(s, sizeof(char), strlen(s), fp);

    fclose(fp);
 
    return 0;
}

/*
run: (the content of d:\\date.bin)

C Programming

*/


answered Oct 20, 2014 by avibootz

Related questions

1 answer 280 views
1 answer 173 views
2 answers 252 views
2 answers 227 views
1 answer 170 views
1 answer 200 views
200 views asked Dec 29, 2020 by avibootz
...