Используйте fwrite
, fputc
, fprintf
или fputs
, в зависимости от того, что вам нужно.
С fputc
вы можете поставить char
:
FILE *fp = fopen("filename", "w");
fputc('A', fp); // will put an 'A' (65) char to the file
С fputs
вы можете поместить массив char
(строка):
FILE *fp = fopen("filename", "w");
fputs("a string", fp); // will write "a string" to the file
С помощью fwrite
вы также можете записать двоичные данные:
FILE *fp = fopen("filename", "wb");
int a = 31272;
fwrite(&a, sizeof(int), 1, fp);
// will write integer value 31272 to the file
С помощью fprintf
вы можете записывать отформатированные данные:
FILE *fp = fopen("filename", "w");
int a = 31272;
fprintf(fp, "a's value is %d", 31272);
// will write string "a's value is 31272" to the file