You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
736 B
34 lines
736 B
/* バイナリデータ(short型)を読み込み、整数値のテキストを出力
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main ( int argc, char *argv[] ) {
|
|
short x;
|
|
FILE *fp = NULL;
|
|
/* file open */
|
|
if ( argc > 1 ) {
|
|
fp = fopen ( argv[1], "rb" );
|
|
if ( fp == NULL ) {
|
|
fprintf ( stderr, "File open error (%s)\n", argv[1] );
|
|
exit ( 1 );
|
|
}
|
|
} else {
|
|
fprintf ( stderr, "Usage: %s input-filename\n", argv[0] );
|
|
exit ( 1 );
|
|
}
|
|
|
|
/* read & write */
|
|
while ( fread ( &x, sizeof ( short ), 1, fp ) == 1 ) {
|
|
printf ( "%d\n", x );
|
|
}
|
|
|
|
/* file close */
|
|
fclose ( fp );
|
|
return 0;
|
|
}
|
|
/* EOF */
|
|
/*
|
|
$ gcc -o bin2ascii-fopen bin2ascii-fopen.c
|
|
$ bin2ascii-fopen sample01.sw > sample01.asc
|
|
*/
|
|
|