I have written a piece of code to reverse a sentence by reversing individual words at a time..
I have tried it and it works fine.
Though it works fine I think the code can be improved further. Can someone help me optimize it.
void reverseWords( char* );
char string = "String to reverse";
printf("\nOriginal string is : %s\n", string);
reverseWords( string );
printf("\nReverse string is : %s\n", string);
void reverseWords( char* string )
char *start = string;
char* end = start;
char* endPtr = string;
while(*endPtr != '\0')
start = endPtr;
end = endPtr;
if(*end == '\0')
endPtr = end;
temp = *start;
*start = *end;
*end = temp;