0

My answer to pig Latin quiz in sololearn. Any suggestions for improvements?

Question: You have two friends who are speaking Pig Latin to each other! Pig Latin is the same words in the same order except that you take the first letter of each word and put it on the end, then you add 'ay' to the end of that. ("road" = "oadray") Task Your task is to take a sentence in English and turn it into the same sentence in Pig Latin! Input Format A string of the sentence in English that you need to translate into Pig Latin. (no punctuation or capitalization) Output Format A string of the same sentence in Pig Latin. Sample Input "nevermind youve got them" Sample Output "evermindnay ouveyay otgay hemtay" https://code.sololearn.com/cd6s6OddYaj2/?ref=app

2nd Jun 2021, 7:21 AM
Rishi
Rishi - avatar
7 Answers
+ 2
My suggestion is to use fgets instead of gets. fgets(str, 100, stdin); gets() is not safe to use because it does not check the array bound. fgets() is a safer version of gets() where you can provide limitations on input size.
2nd Jun 2021, 7:36 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
The future is now thanks to science[INACTIVE] yeah but how do we find the number of input charcters? edit: also change the "inactive" in your name as you're active now
2nd Jun 2021, 7:39 AM
Rishi
Rishi - avatar
+ 1
@Rishi using strlen() you can get the number of input characters. In fgets() you should give the number of input characters that could be maximum. Answering the line:"also change the "inactive" in your name as you're active now" I am not fully active because I am not using the sololearn app. Sololearn app has a lot of features that cannot be used in sololearn web. So that's why my status is inactive.If you go to my profile I think you will see there is a 0-day coding steak. Thanks.
2nd Jun 2021, 8:43 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
The future is now thanks to science[INACTIVE] strlen() can only find the length of a string right? How can it get the number of input characters? Okay don't forget to change it when you use the app:)
2nd Jun 2021, 1:41 PM
Rishi
Rishi - avatar
+ 1
The future is now thanks to science[INACTIVE] oh yes yes I get it. Thank you for making me aware of this. Happy Life!
3rd Jun 2021, 10:49 AM
Rishi
Rishi - avatar
0
Alireza Ebrahimi nice and short code. Thank you
2nd Jun 2021, 7:41 AM
Rishi
Rishi - avatar
0
What do you mean by strlen() can only find the length of a string? The length of a string means the number of input characters when you use fgets() it takes the whole sentence as a string: hello world everyone. how many characters are there? In hello there are 5 characters In world there are 5 characters In everyone there are 8 characters and there are also two gaps and 1 full stop. so extra 3 characters so the total length of the whole sentence is: 5+5+8+3=21 Here is the code: https://code.sololearn.com/c9A7a9a117a1 But of course, there is one problem if you give gaps at the end of the input it will also take those as characters. Hope this helps.
3rd Jun 2021, 9:05 AM
The future is now thanks to science
The future is now thanks to science - avatar