Pages

Wednesday, 8 June 2011

Reverse a string in place. Use pointers rather than array indexing.


Reverse a string in place. Use pointers rather than array indexing.
void revstr(char *str) {
char t;
char *inc_p = str;
char *dec_p = &str[strlen(str)-1];
while(inc_p <= dec_p) {
t = *inc_p;
*inc_p++ = *dec_p;
*dec_p-- = t;
}
}

0 comments:

Post a Comment

Search This Blog