Simple Sand Samples |
C言語 > バイナリデータをファイルへ書き込む
write-bin.c
#include <stdio.h> int main(int argc, char* argv[]) { FILE *fp = fopen(argv[1],"wb"); fputc(1,fp); fputc(2,fp); fputc(3,fp); fclose(fp); return 0; }
$ gcc write-bin.c
$ ./a.out hoge.bin
$ od -tx1 hoge.bin
0000000 01 02 03
0000003
$
$ ./a.out hoge.bin
$ od -tx1 hoge.bin
0000000 01 02 03
0000003
$
* 確認環境 Debian Linux(Wheezy)