jinyedge's note
{http://www.jinyedge.pe.kr}
Hi, this is jinyedge. I'm a software developer.
I hope you can find some useful information
in my homepage.
jinyedge at gmail.com
Since 2001.12.05
|
|
| Subj: C, urldecode. |
|
|
Mtime: 2009-10-21 23:56:35 |
|
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//------------------------------------------------------------------
static int x2i(int i){
i = toupper(i);
i = i - `0`;
if(i > 9){
i = i - `A` + `9` + 1;
}
return i;
}
//------------------------------------------------------------------
static int urldecode(char* s){
int c, c1, n;
char *s0,*t;
t = s0 = s;
n = strlen(s);
while(n > 0){
c = *s++;
if(c == `%` && n > 2){
c = *s++;
c1 = c;
c = *s++;
c = 16 * x2i(c1) + x2i(c);
n -= 2;
}
*t++ = c;
n--;
}
*t = 0;
return t - s0;
}
//------------------------------------------------------------------
int main(int argc, char *argv[]){
char line[128] = "%ED%95%9C%EA%B8%80";
urldecode(line);
puts(line);
return 0;
}
|
|
|
|
|