+ 1

About pig latin problem

I'm stuck with this code... Inspite of my output bring right 5/5 tests have failed .. please help ? #include <stdio.h> #include<string.h> int main() {int i,j,n,k=0,l=0; char a[100]; fgets(a,100,stdin); n=strlen(a); for (i=0;i<n;i++) { if(a[i]==' ') k++; } for (i=0;i<k+1;i++) { for (j=l+1;a[j]!=' ';j++) { if(j<=n) {printf("%c",a[j]);}} printf("%cay",a[l]); l=j+1; if (i<k) printf(" "); } return 0; }

21st Apr 2020, 6:35 PM
Monika
5 Answers
0
You are not outputting the way it should be then ,check the test 1 and test 2 results ,it should tell you the errors
21st Apr 2020, 6:38 PM
Abhay
Abhay - avatar
21st Apr 2020, 6:40 PM
Monika
0
Monika By your code this statement for (j=l+1;a[j]!=' ';j++) It is going to Infinite loop... So to stop it, add like a[n] = ' ' ; a space at last to input...
21st Apr 2020, 6:56 PM
Jayakrishna 🇮🇳
Jayakrishna 🇮🇳 - avatar
0
Jayakrishna🇮🇳 Thank you soo much a[n]=' ' .Fixed the problem
21st Apr 2020, 7:02 PM
Monika
0
Monika you're welcome..
21st Apr 2020, 7:04 PM
Jayakrishna 🇮🇳
Jayakrishna 🇮🇳 - avatar