#include?<stdio.h>
#include?<stdlib.h>
#include?<string.h>
#define?LENGTH?100 /*字符串(編碼前或編碼後)的最大長度*/
/*編碼*/
voidencode(char*strsource);
/*解碼*/
voiddecode(char*strcode);
void?main()?
{?
char?code[LENGTH]="BILL?GATES";?
encode(code);
printf("\nencoded?string?is:%s\n",code);
decode(code);
printf("\ndecoded?string?is:%s\n",code);
getch();
}
void?encode(char?*strsource){
char?*p=strsource,tmp[LENGTH]={'\0'},buffer[3];?
while(*p){
itoa(*p++,buffer,10);
strcat(tmp,"%");
strcat(tmp,buffer);?
}?
strcpy(strsource,tmp);
}
void?decode(char?*strcode){
int?i=0;
char?*p,*s=strcode,tmp[LENGTH]={'\0'};
char?*cSplit="%";
p=strtok(s,cSplit);
while(p)
{
tmp[i++]?=?atoi(p);
p=strtok(NULL,cSplit);
}
strcpy(strcode,tmp);
}