+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

1/20/2020 9:31:14 AM

Hack001

6 Answers

New Answer

+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

+1

sizeof(input) is not an issue. sizeof(char) is 1 so sizeof(char array) will return sizeof array. Why are you checking for 'a', 'y' and '.' in the input? strcpy(str2, Store[k])? second argument needs to be a string, Store[k] is a character ! There might be more issues, i have only checked that much as of now. quite a complicated code for simple task. But probably you are learning so it's ok for the time being.

+1

Ok i got what you are doing, but the problem is strcpy here.

0

Taste Ok, thanks, I'll change that and check again

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.

0

thankyou for giving information