#include <stdlib.h>
#include <stdio.h>
int main(void)
{
int flag = EXIT_SUCCESS;
char file_name[] = "d:\\data.bin";
char str[] = "A text for binary file";
FILE *fp = fopen(file_name, "wb");
if (fp == NULL)
{
flag = EXIT_FAILURE;
fprintf(stderr, "fopen() error\n");
}
else
{
size_t size = sizeof * str;
size_t total = sizeof str;
size_t total_written = fwrite(str, size, total, fp);
if (total_written != total)
{
flag = EXIT_FAILURE;
fprintf(stderr, "fwrite() error: wrote only %I64d from %I64d\n", total_written, total);
}
fclose(fp);
}
return flag;
}
/*
run:
*/