Reverse of individual words in the given string. Nov, 2020
Solution in C PYTHON
#include<stdio.h>
int main() {
char str[50],temp;
int i,j,k=0;
fgets(str,50,stdin);
for(i=0;str[i]!='\0';i++){
if(str[i+1]=='\0'){
for(j=i-1;k<=j;k++,j--){
temp = str[k];
str[k] = str[j];
str[j] = temp;
}
str[i] = ' ';
k=i+1;
}
if(str[i]!=' ')
continue;
else{
for(j=i-1;k<=j;k++,j--){
temp = str[k];
str[k] = str[j];
str[j] = temp;
}
str[i] = ' ';
k=i+1;
}
}
str[i] = '\0';
puts(str);
}
int main() {
char str[50],temp;
int i,j,k=0;
fgets(str,50,stdin);
for(i=0;str[i]!='\0';i++){
if(str[i+1]=='\0'){
for(j=i-1;k<=j;k++,j--){
temp = str[k];
str[k] = str[j];
str[j] = temp;
}
str[i] = ' ';
k=i+1;
}
if(str[i]!=' ')
continue;
else{
for(j=i-1;k<=j;k++,j--){
temp = str[k];
str[k] = str[j];
str[j] = temp;
}
str[i] = ' ';
k=i+1;
}
}
str[i] = '\0';
puts(str);
}
hello how are you
olleh woh era uoy