现在的位置: 首页 > 综合 > 正文

CGI做中文处理时的问题!

2013年06月09日 ⁄ 综合 ⁄ 共 688字 ⁄ 字号 评论关闭
#include   <stdio.h>  
  #include   <stdlib.h>  
   
  int   main(void)  
  {  
    unsigned   int   i=0,max=30;  
    char*   dest;  
    dest=(char*)malloc(max);  
    if(!dest)exit   (1);  
    printf("input   your   code   string:   ");  
    while((dest[i]=getchar())=='%')  
    {  
  if((dest[++i]   =getchar())   >=   'A')  
  dest[i]   =   ((dest[i]   &   0xdf)   -   'A')   +   10;  
  else  
  dest[i]   =   dest[i]   -   '0';  
  if((dest[++i]   =getchar())   >=   'A')  
  dest[i]   =   ((dest[i]   &   0xdf)   -   'A')   +   10;  
  else  
  dest[i]   =   dest[i]   -   '0';  
  dest[i/3]=dest[i]+dest[i-1]*16;  
  i++;  
  if(i==max)  
  {  
  max+=max;  
  dest=(char*)realloc(dest,max);  
  if(!dest)   exit(1);  
  }  
    }  
    dest[i/3]='\0';  
    printf("this   decode   string   is:%s\n",dest);  
    free(dest);  
    return   0;  
  }  
   
   
  献丑了:)  
   
  你输入一段%**%**   试试

抱歉!评论已关闭.