This is ridiculous
Code:
for (i=0;i<length-1;i++) fromBack++; //move pointer to end of string
when this will do
Code:
fromBack += length - 1;
And you don't need i (or length) :
Code:
void ReverseString(char* String) {
char* fromFront = String;
char* fromBack = String + strlen(String) - 1;
char temp;
while (fromFront < fromBack) {
temp = *fromBack; *fromBack = *fromFront; *fromFront = temp;
fromBack--;
fromFront++;
}
}
The reason your code doesn't work is because you're calling the routine with a pointer to a string constant. Try calling it like this:
Code:
int main(void) {
char hi[] = "jewel"; // give the string some writable storage
ReverseString(hi);
puts(hi);
return 0;
}