1. 程式人生 > >十六進位制字元轉對應的十六進位制數

十六進位制字元轉對應的十六進位制數

#include <stdio.h>
#include <string.h>


/* C 庫函式 int feof(FILE *stream) 測試給定流 stream 的檔案結束識別符號。 */


int main( void )
{
	unsigned char	tmp;

	FILE	*infp;
	FILE	*outfp;


	infp	= fopen( "in.txt", "r" );
	outfp	= fopen( "out.txt", "wb" );

	/* 這邊要先讀再判斷,不然會多出一個位元組 */
	fscanf( infp, "%X",
&tmp ); while ( !feof( infp ) ) { putc(tmp,outfp); fscanf( infp, "%X", &tmp ); } fclose( infp ); fclose( outfp ); return(0); }