本文共 2156 字,大约阅读时间需要 7 分钟。
XDR-变长类型数组-空间管理-log
2014年4月8日23:39:02
.x文件:
enum colors{ RED = 2, YELLOW = 3, BLUE = 5, GREEN = 0x10};struct lww_int{ int m_nAge; bool m_bMale; string m_sName<255>; colors m_ayColor[2]; int m_naNum<4>;};union lww_union switch(colors clr){case RED: int m_nAge;case YELLOW: bool m_bMale;case BLUE: string m_sName<255>;case GREEN: colors m_ayColor[2];};C程序:
#include#include #include "lww.h"//int main()//{// printf("begin\n");//// FILE * pFile = fopen("lww.txt","wb");// XDR XDR;// xdrstdio_create(&XDR,pFile,XDR_ENCODE);//// colors aRED = RED;// colors aYELLOW = YELLOW;// colors aBLUE = BLUE;// colors aGREEN = GREEN;// lww_int aLwwInt;// aLwwInt.m_nAge = 28;// aLwwInt.m_bMale = TRUE;// aLwwInt.m_sName = (char *)"1234";// aLwwInt.m_ayColor[0] = GREEN;// aLwwInt.m_ayColor[1] = BLUE;//// int naInt[2];// naInt[0] = 1;// naInt[1] = 2;// aLwwInt.m_naNum.m_naNum_len = 2;// aLwwInt.m_naNum.m_naNum_val = naInt;//// lww_union aLwwUnion;// aLwwUnion.clr = RED;// aLwwUnion.lww_union_u.m_nAge = 28 * 2;//// xdr_colors(&XDR,&aRED);// xdr_colors(&XDR,&aYELLOW);// xdr_colors(&XDR,&aBLUE);// xdr_colors(&XDR,&aGREEN);// xdr_lww_int(&XDR,&aLwwInt);// xdr_lww_union(&XDR,&aLwwUnion);//// xdr_destroy(&XDR);// fclose(pFile);//// printf("end\n");//// return 0;//}void printColor(colors aColor){ switch(aColor) { case RED: printf("红色\n"); break; case YELLOW: printf("黄色\n"); break; case BLUE: printf("蓝色\n"); break; case GREEN: printf("绿色\n"); break; default: printf("错误色\n"); break; } return;}void printBool(bool_t bPrint){ switch(bPrint) { case TRUE: printf("真\n"); break; case FALSE: printf("假\n"); break; default: printf("错误\n"); break; } return;}lww_int aLwwInt;void writeTLogFile(char * str){ FILE * pFileW = fopen("log.txt","a+"); if(NULL == pFileW) { return; } fprintf(pFileW,"%s\n",str); fclose(pFileW); return;}void writeBLogFile(char * str,int nCount){ FILE * pFileW = fopen("log.txt","ab+"); if(NULL == pFileW) { return; } fwrite(str,1,nCount,pFileW); fclose(pFileW); return;}void writeB2TLogFile(char * str,int nCount){ char sBuffer[400] = {0}; strcpy(sBuffer,"0X"); char * pBuffer = sBuffer + 2; for(int i = 0;i
转载地址:http://unwci.baihongyu.com/