写一个fwrite写入二进制文件
时间: 2023-10-10 22:12:14 浏览: 160
C语言fseek、fread、fwrite读写二进制文件
#include <stdio.h>
int main() {
FILE *fp;
int arr[] = {1, 2, 3, 4, 5};
int size = sizeof(arr) / sizeof(int);
fp = fopen("output.bin", "wb");
if (fp == NULL) {
printf("Failed to open file.\n");
return 1;
}
fwrite(arr, sizeof(int), size, fp);
fclose(fp);
return 0;
}
阅读全文