+ 2

Why is this code giving timeout error? (C)

So, I wrote this program to decode Pig Latin (e.g : Input = "igpay atinlay." → final output = "pig latin." (Opposite of one of the CodeCoach problems) I'm considerably new with C, and am finding string operations a real pain, and here, I have no clue as to why it's showing timeout error. Any help would be highly appreciated. https://code.sololearn.com/cFMP69CSyte8/?ref=app

20th Jan 2020, 9:31 AM
Hack001
Hack001 - avatar
6 Respuestas
+ 1
one problem i can spot is you're using sizeof as condition in for loop. sizeof return a memory space of your variable, if its an array then the size times array size. so lets say sizeof single char return 4, then whats the sizeof an array of 2000 char ? yes 8000! so you're basicly looping for 8000times several times
20th Jan 2020, 10:05 AM
Taste
Taste - avatar
0
Taste Ok, thanks, I'll change that and check again
20th Jan 2020, 10:35 AM
Hack001
Hack001 - avatar
0
~ swim ~ Thanks for helping me out. I'm checking for 'a', 'y' followed by a ' ' or '.' as I wish to remove those characters from the input string (eg : ayI ovelay odingcay. → I love coding.) Ok, I get it, I'll try and fix that part of strcpy. I realise I am making it overly complicated, I'm very new to C, barely a couple of weeks in, so I'm still trying to wrap my head around most of the things. I'll try to make the codes more precise and cleaner from now on. Thanks again for your advice.
20th Jan 2020, 1:43 PM
Hack001
Hack001 - avatar
0
thankyou for giving information
21st Jan 2020, 10:00 AM
Bhavana
Bhavana - avatar