i want a program which reverse given string in the below format. Suppose if I input string as = "This is a boy" then i want output reverse sting as = "boya si ishT"
one more example Input string = "if a" Output String = "af i" please help. i have written below program but not working as expected.
char string[] = "This is a boy\0";
char reverse[100] = {0};
int start = 0;
int len = strlen(string)-1;
int space= 0;
bool flag = false;
int count = 0;
while(len >= 0)
{
if(string[len] == ' ' )
{
len--;
flag = true;
}
if(flag && (string[len-1]) == ' ')
{
reverse[start] = string[len];
reverse[++start] = ' ' ;
len--;
start++;
flag = false;
continue;
}
reverse[start] = string[len];
flag = false;
start++;
len--;
}