convertHex changes all occurrences of %XX (XX are exactly two hexadecimal digits) to ascii characters. Returns the number of replacements made.
Here are the rules:
Except when defining your character arrays, you must use pointer notation for all c-string manipulation--no []'s allowed. You may use any function from the cctype library, but only strlen(), strstr(), and strncmp() from the cstring library. The C++ string class may not be used.
Here is my stub function:
int convertHex(char *words){
int changed = 0;
return changed;
}
I'm thinking the resulting function needs to look like the following function:
//Replace the second string parameter with the third string parameter in the string
int replaceText(char *words, char *replace, char *check){
char *location;
int count = 0,
value = 0,
shift,
adjust,
length = strlen(words),
difference;
bool found = false;
if (strlen(replace) < strlen(check))
return 0;
else
difference = strlen(replace) - strlen(check);
do{
location = strstr(words, replace);
if (location != NULL){
found = true;
shift = location - words;
*(words + shift) = *check;
for (adjust = shift + 1; adjust < length; adjust++){
*(words + adjust) = *(words + adjust + difference);
}
count++;
}
else
found = false;
}while (found);
return count;
}
Having trouble figuring out what to do once I locate the '%'.
How can I convert the hex characters to a single ascii character and then put that character back into the string?