컴퓨터공부/C & C++ & STL

스트림을 읽어 들여서 보자..

achivenKakao 2007. 5. 17. 00:47

#include<stdio.h>
#include<stdlib.h>

int main()
{
 void *buf;

 FILE *infp = fopen("ezboot.x5", "rt");
 FILE *outfp = fopen("out_ezboot.x5", "w+");

 buf = malloc(4*4);  // 32bits

 fread(buf, 1, 4, infp);
 fwrite(buf, 1, 4, outfp);

 printf("%x", *(int*)buf);
}

뭐.. 별거 없는 코드이다..

끝에 void 형인 buf를 캐스팅 연산을 이용하여 출력할 수 있게 해준다는 것을 빼먹지 말자..

printf에서는 void형은 출력못하니 int * 로 형변환을 한 다음에 안에 있는 데이터를 출력한다.