+ 1

#include <stdio.h> #include <string.h> int main() { char a[100]; int i,j,b=0,c; gets(a); c=strlen(a); for(i=0;i<c;i++)

Why it is not working for more than 2 words in medium level problem code coach pig latin

11th Mar 2020, 9:43 AM
Allepu Madhan mohan
Allepu Madhan mohan - avatar
7 Answers
+ 3
Your code is incomplete. Copy paste the code in code playground and post it here.
11th Mar 2020, 9:51 AM
Arsenic
Arsenic - avatar
+ 1
Don't put code in question title
11th Mar 2020, 9:50 AM
Gordon
Gordon - avatar
+ 1
Gordon Arsenic (This is not the answer) Here's the code... Fix it Got it from the post https://www.sololearn.com/post/263285/?ref=app #include <stdio.h> #include <string.h> int main() { char a[100]; int i,j,b=0,c; gets(a); c=strlen(a); for(i=0;i<c;i++) { if(a[i]!=' '){b++;} else if(a[i]=' '){ for(j=i-(b-1);j<i;j++){printf("%c",a[j]);} printf("%cay ",a[i-b]); b=0;} } return 0; }
11th Mar 2020, 10:10 AM
Utkarsh Sharma
Utkarsh Sharma - avatar
+ 1
Allepu Madhan mohan You printing when space encounters but since if there is no space after last word, it is missing printing last word..
11th Mar 2020, 3:00 PM
Jayakrishna 🇼🇳
0
#include <stdio.h> #include <string.h> int main() { char a[100]; int i,j,b=0; gets(a); int c=strlen(a); a[c]=' '; for(i=0;i<=c;i++) { if(a[i]!=' '){b++;} else if(a[i]=' '){ for(j=i-(b-1);j<i;j++){printf("%c",a[j]);} printf("%cay ",a[i-b]); b=0;} } return 0; }
11th Mar 2020, 4:53 PM
Allepu Madhan mohan
Allepu Madhan mohan - avatar
0
Thanks to all I got it by adding a[c]=' '
11th Mar 2020, 4:54 PM
Allepu Madhan mohan
Allepu Madhan mohan - avatar
0
def abc(str): q='' r=str.split( ) for i in r: p=i[1:]+i[0]+'ay'+' ' q=q+p print(q) g=input() abc(g)
13th Mar 2020, 6:04 AM
Rajaram Ajay
Rajaram Ajay - avatar