// file_operate_test.cpp : 定義控制檯應用程序的入口點。
//
#include "stdafx.h"
#include "stdlib.h"
#include <string.h>
#include <stdio.h>
#define byte unsigned char
using namespace std;
typedef struct A{
unsigned int para1;
unsigned short para2;
unsigned int para3;
unsigned short para4;
}A;
int _tmain(int argc, _TCHAR* argv[])
{
// printf(“hello world!! sizeof = %d \n”,sizeof(int));
// system(“pause”);
//return 0;
int a[100];
byte *p;
int i = 0;
int j = 0;
A test4;
test4.para1 = 20;
test4.para2 = 15;
test4.para3 = 20;
test4.para4 = 15;
p = (byte*)(&test4);
FILE* fp=fopen("d:\\new_2.dat","r");
FILE* fw=fopen("d:\\new_3.dat","w");
FILE* fw2=fopen("d:\\new_4.dat","w");
if(fp==NULL)
{
printf("無文件");
return -1;
}
while(!feof(fp))
{
fscanf(fp,"%x",&a[i]);
if(a[i] == 0xcccccccc){break;}
printf("十六進制 %x ,十進制 %d ",a[i],a[i]);
fputs("0x",fw);
fprintf(fw,"%x\n",a[i]);
i++;
printf("\n");
}
printf("unsigned short = %d, int = %d",sizeof(unsigned short),sizeof(int));
printf("i ======== %d\n", i);
for(i=0;i<8;i++)
{
//if(i%2 == 0 ){printf("\n");}
printf("%x\n",p[i]);
fputs("0x",fw2);
fprintf(fw2,"%0x\n",p[i]);
}
fclose(fp);
fclose(fw);
fclose(fw2);
system("pause");
return 0;
}