ファイル内容バイナリ表示プログラム



[ 簡単な説明 ]

file の内容をバイト毎に16進表示するプログラムです。

watch   file

として使用します。


プログラム・ソース("watch.c")           top (トップに戻る)
/*		watch.c		Binary File watching	*/
#include <stdio.h\>

main(int argc, char *argv[])
{
	FILE *fp;
	char buf[16], *p;
	int i;

	if(argc < 2)
	{
		fprintf(stderr, "Usage : %s  file\n", argv[0]);
		fprintf(stderr, "Function : watching binary file.\n");
		exit(0);
	}
	fp = fopen(argv[1], "rb");
	if(fp == NULL)
	{
		fprintf(stderr, "Error : file(%s) can't open.\n", argv[1]);
		exit(-1);
	}

	while((i = fread(buf, sizeof(char), 16, fp)) != 0)
	{
		p = buf;
		do
		{
			printf("%02x ", *p++ & 0xff);
		} while(--i);
		putchar('\n');
	}
}