Accidentals inside a bar
Sometimes a sharp, flat or natural turns up in the middle of the music, attached to one note. That's an accidental — a local change, not a standing one. It changes that note, and it keeps changing every note on the same line or space until the next bar line. The bar line wipes it, back to the key signature.
A natural cancels the key, too
An accidental doesn't only add sharps and flats — a ♮ in a sharp key takes a note the key signature had raised and drops it back to natural, for the rest of that bar.
Scan the bar first
Before you play a bar, look through it. A sharp early in the bar can still be in force on a later note that has no sign of its own. Miss it and you play a wrong note without knowing why.
The courtesy accidental — a ♮ or ♯ in brackets, or just restated at a bar line (like the ♯ on bar 2 above) — is a reminder of where things stand, not a new instruction.
The usual mistake
Two of them: carrying an accidental past the bar line (it's already gone), and forgetting it applies to the rest of the bar (it's still there).
The reading habit
Key signature first, then local accidentals, bar by bar. That order, every time.
Try
Play the line above. In bar one, feel the 2nd finger stay forward (high) for both C's. At the bar line, let it fall back. That physical reset is the rule.