Are both line 36 and 37 supposed to be inside the if loop?
If so, inclose them with brackets. If there are no brackets, the if statement only extends to the first statement.
I didn't debug your code, but I think the problem is with your x variable, you might be incrementing past the bounds of s[] or s2[].
Try using a debugger or use print statements to see the value of x before you assign a value to s[x].
Write many simple, small functions. Test each function to make sure it works correctly before moving on to the next one.Take baby steps. Particularly when you are learning programming.
(Ignore performance, unless it really is a constraint. 'When in doubt, use brute force'.)