+ 1

Pig Latin Problem in C

Anyone help with this code problem. Changing English to Pig Latin . 1) Moving first letter of the word to the last 2) Adding ay at the end of the word. Small —> mallsay https://code.sololearn.com/cULC8c9PDt0P/?ref=app

12th Jan 2023, 9:27 AM
Wakil Ah Hamidi
Wakil Ah Hamidi - avatar
9 Réponses
+ 1
#include <stdio.h> #include<string.h> int main() { char str[25]; scanf("%s",str); //fgets(str,25,stdin); // use fgets instead of gets, for reading line of string.. for single word use scanf // you can just print 1 to end of string chars. for(int i=1; i<(int)strlen(str); i++) { printf("%c", str[i]); } // first letter, with "ay" printf("%cay", str[0]); return 0; } // you are working for single word so use scanf just.. edit: Wakil Ahmad Hamidi oh. need to expand? for words : set first char into a variable. char c = str[0]; in loop, from 1 to end, print if is not space, otherwise print first letter c+"ay", and change first char c to next char c = str[i++]; and there is a string function for splitting strings by a delimiter strtok(); . you can learn about this.
12th Jan 2023, 11:43 AM
Jayakrishna 🇮🇳
+ 3
Your if condition is missing || for last condition.. But actually, why you need to check for vowels, if you just need to change first char to last?
12th Jan 2023, 9:49 AM
Jayakrishna 🇮🇳
+ 3
Wakil Ahmad Hamidi, Jayakrishna🇮🇳 the first loop can be replaced with a single printf statement. printf("%s", &str[1]); Or equivalently with this: printf("%s", str+1); After that, you can even combine both print statements into one. print("%s%cay ", &str[1], str[0]); (EDIT: added a space at the end to separate the next word) Now the only thing the code is missing is a loop to process the remaining words in the input. Add a while loop that repeats until scanf returns EOF.
12th Jan 2023, 11:54 PM
Brian
Brian - avatar
+ 2
Actually I remember your prev suggestion of not making changes in original code bit 😊 So I tried it in my computer and left that as it was New one looks something like this: https://code.sololearn.com/c62HO88zaLZS/?ref=app (Only for words, need to be improved for sentence) Jayakrishna🇮🇳
12th Jan 2023, 11:18 AM
Wakil Ah Hamidi
Wakil Ah Hamidi - avatar
+ 2
Yes. Brian that's also works. Better way to use in next level..
13th Jan 2023, 8:34 AM
Jayakrishna 🇮🇳
+ 1
Jayakrishna🇮🇳 Yeah I see Checking for vowel is required but not here, thats why I removed.
12th Jan 2023, 10:31 AM
Wakil Ah Hamidi
Wakil Ah Hamidi - avatar
+ 1
I don't understanding.. Is it working now with changes..? Fine. If working..
12th Jan 2023, 10:37 AM
Jayakrishna 🇮🇳
+ 1
Jayakrishna🇮🇳 I am saying that I made changes in my computer code editor not sololearn (problem). So that when any one see, they can recognise where the mistake was And now solved is here, but need some improvment for sentence translation https://code.sololearn.com/c62HO88zaLZS/?ref=app
12th Jan 2023, 11:30 AM
Wakil Ah Hamidi
Wakil Ah Hamidi - avatar
0
That's ok. But that your reply was not clear to me.. Add "solved, working,.. " to be clear. 👍.
12th Jan 2023, 11:24 AM
Jayakrishna 🇮🇳