walk the original string, copying characters to a new string, if a
special character is encountered (SPACE or @) instead copy the ASCII value description.
Inefficient but easy to read--%26gt;
char string1[12] = "Hello World";
char string2[36] = ""; /* enough to convert every character! */
for (i=0, j=0; i%26lt;strlen(string1);i++)
{ if (string1[i] == ' ')
strcat(string2, "%20");
else if (string1[i] == '@')
strcat(string2, "%40");
else
strcat(string2, string1+i);
}
(did I remember the ascii values correctly?)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment