CGI做中文处理时的问题!
#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;
}
献丑了:)
你输入一段%**%** 试试
#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;
}
献丑了:)
你输入一段%**%** 试试