I am working on a program for my comp sci classes and the problem asks to take a command from the user and the string that. Then, use either "reverse " to reverse the string that follows or "create " to print the string that follows. The reverse output should keep the words reverse, then print the string that follows in reverse.
/* for Reverse command */
else if(strcmp(str,"reverse ") > 0)
{
reverse(str);
printf("Reverse of string: %s\n", str);
}
The following function is used to reverse the word:
void reverse(char *string)
{
int length, i;
char *begin, *end, temp;
length = strlen(string);
begin = string;
end = string;
for (i = 0 ; i < (length - 1) ; i++)
end++;
for (i = 0 ; i < length/2 ; i++)
{
temp = *end;
*end = *begin;
*begin = temp;
begin++;
end--;
}
}
The output reverses all the words and prints. Is there a way to break off the reverse part of the string before it is passed to the reverse function?
reverse(). All this is assuming you readreverse hello worldin one string.