You can stay in C major because all the chords are made up with tones that come from the C major scale. C is CEG, Am is ACD, F is FAC, G is GBD. To make your solo sound good, you ought to play the notes of the C scale, but you can also try to 'target' the tones that are in the chord in the background. Also, it's rather difficult to play something musical when practicing a scale. Master the scale, then try to sing the thing aloud. play it on the guitar. After a while, you'll be able to play it WHILE you are singing.