Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1218677
  • 博文数量: 573
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 66
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-28 16:21
文章分类

全部博文(573)

文章存档

2018年(3)

2016年(48)

2015年(522)

分类: C/C++

2015-12-02 16:53:34


点击(此处)折叠或打开

  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>

  4. #define _X_ __LINE__,__FILE__,'1'

  5. void WriteLogHex(const long _line_,const char *_file_,char flag,char *prbuf,long buf_len);

  6. char sDebugFile[128];

  7. int main(int argc, char ** argv)
  8. {
  9.     memset(sDebugFile, 0x00, sizeof(sDebugFile));
  10.     sprintf(sDebugFile, "/home/eas/src/API_fun/log/cli.log");
  11.     
  12.     char buf[1024*10]="5231334\" req_no=\"82012\" from=\"icbc\" to=\"shfe\" trade_type=\"A001\" reply_date=\"20130221\" reply_time=\"11:33:54\" reply_code=\"0\" reply_msg=\"查询成功\" ext_code=\"0\" ext_msg=\"OK\" >\n\t111111111111\" account=\"上海期货交易所\" currency =\"CNY\" branch_no=\"0021\" size=\"10\" >\n\t\t1\" bank_serial=\"N20111113\" trade_date=\"20130221\" trade_time=\"21:11:21\" money_in=\"100000\" money_out=\"0\" opp_account=\"82121233344455\" opp_acct_name=\"XX期货有限公司\" available_balance=\"150000\" balance=\"150000\" post_script=\"张XX网银入金10万\" /> \n\t\t2\" bank_serial=\"N20114334\" trade_date=\"20130221\" trade_time=\"21:13:43\" money_in=\"200000\" money_out=\"0\" opp_account=\"82121233344455\" opp_acct_name=\"XX期货有限公司\" available_balance=\"350000\" balance=\"350000\" post_script=\"张XX网银入金20万\" /> \n\t \n";
  13.     char buf2[1024*10]="D_File:/home/ap/ssbpwlkf/log/SIP_SOCK_CSBS20130418.log^^E_File:/home/ap/ssbpwlkf/log/SIP_SOCK_CSBS20130418.err^^txn_seq_dmz:SDZ2013041800000760^^chnl_flow:SDZ2013041800000760^^txn_time:131721756^^ds_logpid:3211640131721777^^ds_logtxnseq:SDZ2013041800000760^^ds_logtellid:^^ds_logchnlno:CSBS^^ds_logchnltxn:^^ds_logtxncode:^^ds_logacctno:^^ds_logtxnamt:^^time_consume:40^^chnl_code:CSBS^^resp_code:000000^^retmsg:开始传输数据^^filename:/home/ap/ssbpkf/temp/QjsQueryReq_20130418_131721812.xml^^snd_flag:S^^limit_flag:0^^txn_code:1009^^req_no:82012^^from:shfe^^to:icbc^^req_date:20130221^^req_time:21:33:00^^size:4^^acct_no:31001512200059000030^^currency:01^^branch_no:310733600^^txn_seq:82012^^txn_date:20130418^^mfile_flag:0^^curr_code:01^^curr_type:0^^acct_out:31001512200059000030^^";
  14.     char buf3[1024*10];
  15.     char buf4[1024];
  16.     
  17.     printf("buf = \n[%s]\n\n", buf);
  18.     WriteLogHex(_X_, buf, strlen(buf));
  19.     WriteLogHex(_X_, "1111111111111111", strlen("1111111111111111"));
  20.     
  21.     printf("buf2 = \n[%s]\n", buf2);
  22.     WriteLogHex(_X_, buf2, strlen(buf2));
  23.     WriteLogHex(_X_, "2222222222222222", strlen("2222222222222222"));
  24.     
  25.     memset(buf3, 0, sizeof(buf3));
  26.     strcpy(buf3, buf2+410*sizeof(char));
  27.     printf("buf3 = \n[%s]\n", buf3);
  28.     WriteLogHex(_X_, buf3, strlen(buf3));
  29.     WriteLogHex(_X_, "3333333333333333", strlen("3333333333333333"));
  30.     
  31.     memset(buf4, 0, sizeof(buf4));
  32.     strcpy(buf4, "abcde我是王贤才张秋苹");
  33.     printf("buf4 = \n[%s]\n", buf4);
  34.     WriteLogHex(_X_, buf4, strlen(buf4));
  35.     WriteLogHex(_X_, "4444444444444444", strlen("4444444444444444"));
  36.     
  37.     return 0;
  38. }
  39.     
  40. /*************************************************************
  41.  *
  42.  * 函 数 名:WriteLogHex()
  43.  * 功能描述: 16进制日志函数
  44.  * 输入参数:_line_ - 调用此函数的行数
  45.  * _file_ - 调用此函数的文件名
  46.  * flag - 处理标志
  47.  * prbuf - 要写日志的串
  48.  * buf_len - 要写日志串的长度
  49.  * 输出参数:无
  50.  * 返 回:
  51.  * 流程描述:
  52.  * 说明:
  53.  ************************************************************/
  54. void WriteLogHex(const long _line_,const char *_file_,char flag,char *prbuf,long buf_len)
  55. {
  56.     char ymd[12],hms[10];
  57.     unsigned char *p;
  58.     char sdate[11];
  59.     int i,k,j;
  60.     FILE *fp;
  61.     int filelen;

  62.      fp=fopen(sDebugFile,"a");
  63.      if(fp==NULL) return;

  64.     p=(unsigned char *)prbuf;
  65.     fprintf(fp,"\n============= begin:[%s][%d]===============len[%d]\n",
  66.         _file_,_line_,buf_len);
  67.     for(i=0,k=0;i<buf_len;i++)
  68.     {
  69.         if(i==0) fprintf(fp,"%06d> ",i);
  70.         if( (i % 16) == 0 && i != 0)
  71.         {
  72.             fprintf(fp,"> ");
  73.             for(j=0;j<16;j++)
  74.             {
  75.                 if( (p[16*k+j] == '\0' ) ||(p[16*k+j] == '\n') ||
  76.                     (p[16*k+j] < ' ') )
  77.                     fprintf(fp,".");
  78.                 else
  79.                     fprintf(fp,"%c",p[16*k+j]);
  80.             }
  81.             fprintf(fp,"\n");
  82.             fprintf(fp,"%06d> ",i);
  83.             k++;
  84.         }
  85.         fprintf(fp,"%02x ",p[i]);
  86.     }
  87.     if(16 * k < i)
  88.     {
  89.         for(j =0;j< (16 + 16 * k - i) * 3;j++)
  90.              fprintf(fp," ");
  91.          fprintf(fp,"> ");
  92.         for(j=0;j< i - 16 * k;j++)
  93.         {
  94.             if( (p[16*k+j] == '\0' )||(p[16*k+j] == '\n') ||
  95.                 (p[16*k+j] < ' ') )
  96.                 fprintf(fp,".");
  97.             else
  98.                 fprintf(fp,"%c",p[16*k+j]);
  99.         }
  100.     }
  101.     fprintf(fp,"\n============== buf end: ================\n");
  102.     fprintf(fp,"\n");
  103.     fclose(fp);
  104.     return ;
  105. }

阅读(569) | 评论(0) | 转发(0) |
0

上一篇:字符串翻转函数

下一篇:stat函数

给主人留下些什么吧!~~