缓冲区存取数据


BYTE * funsave(BYTE *bytebuf) // 将数据保存到buf中
{
 float f = 76;
 byte b = 0;
 double d = 2.543;
 int i = 99;
 SYSTEMTIME s;
 s.wDay = 20;
 s.wHour = 8;
 s.wMilliseconds = 12;
 s.wMinute = 10;
 s.wMonth = 5;
 s.wSecond = 34;
 s.wYear = 2010;
 
 bytebuf = &b;
 *((float*)(bytebuf+1)) = f;
 *((byte*)(&f+1)) = b;
 *((double*)(&b+1)) = d;
 *((int*)(&d+1)) = i;
 *((SYSTEMTIME*)(&i+1)) = s;
 
 return bytebuf;
}

void main()
{
 // 在bytebuf 中保存各个类型值
    BYTE *bytebuf = NULL;
 bytebuf = funsave(bytebuf);
}
/*
一缓冲区 依次存放char[32],FLOAT,BYTE,DOUBLE,INT ,SYSTEMTIME
现有一个 byte* 指向开头,如何依次取出放入变量中
*/
typedef   unsigned   char   BYTE;
void funbuf(BYTE *p)
{
 char* cr = (char*)p;
 float* pfloat = (float*)(cr+sizeof(char)*32);
 byte* pbyte1 = (byte*)(cr+sizeof(char)*32+sizeof(float));
 double* pdouble = (double*)(cr+sizeof(char)*32+sizeof(float)+sizeof(byte));
 int* pint = (int*)(cr+sizeof(char)*32+sizeof(float)+sizeof(byte)+sizeof(double));
 SYSTEMTIME* pSYSTEMTIME = (SYSTEMTIME*)(cr+sizeof(char)*32+sizeof(float)+sizeof(byte)+sizeof(double)+sizeof(int));
}

你可能感兴趣的:(缓冲区存取数据)