A melody written using the diatonic notes of a C major scale is commonly said to be 'in C major'. There is, however, more to being 'in' a key than simply using the notes of a given scale. A piece of music becomes tonal by establishing particular relationships between the notes of the scale.
These relationships help create two important pillars of tonal music: triadic harmony and the idea of a tonic. These and other important concepts are explored in the Introduction to Tonality. You might also find Working out the key of a passage helpful.