Reverse a string
Anonymous
local variable i is not used at all strlen called twice pointers can be incremented while accessing char * revstr (char * string ) { if ( NULL == string ) return NULL; char *start = string; // Save point to beginning char *left = string; char ch; while (*string++) // Find end of string ; string -= 2; // Hop back over zero terminator while (left < string) { ch = *left; *left++ = *string; *string-- = ch; } return(start); }
Check out your Company Bowl for anonymous work chats.