#include <stdio.h>
typedef struct _CToStruct
{
char c;
short h;
int i;
}CToSturct;
#define TS_SIZE (5)
//½«½á¹¹ÌåÊý¾ÝдÈëÎļþ
int writeToFile(void* pData,unsigned int size)
{
FILE* fp = fopen("c:\\tostruct.dat","wb");
if(fp == NULL)
return 0;
fwrite(pData,1,size,fp);
fclose(fp);
return 1;
}
int main(int argc, char* argv[])
{
int i = 0;
CToSturct ts[TS_SIZE] = {0};
for(;i < TS_SIZE;i++)
{
ts[i].c = (char)i;
ts[i].h = (short)i * i;
ts[i].i = i* i * i;
}
writeToFile(ts,sizeof(ts));
return 0;
}
|