- Change your strings!
- Either buy a better guitar or have the action gone over on yours
- Practice a lot slower!
Taking these items one by one: guitar strings wear out faster than you think. They have about fifty to sixty hours of use before they start to degrade. The bass strings lose brilliance and the trebles become dented on the frets and start to lose pitch definition. It becomes harder to tune your guitar. Just change your strings and you will instantly sound like a better player! There are lots of good brands on the market. Hannabach is good and so are the strings sold by GSP in San Francisco, their house brand. But I've used Pro Arté a lot and they are excellent and you can get them almost anywhere.
Many guitars have action problems either from the start or developing over time. It might be really worth it to have a good guitar technician look over your guitar. If the strings are exactly the correct height above the frets, it will make playing easier and you will sound like a better guitarist. If your action is good, but you still can't get the sounds you want, time to think about buying a better guitar. Compared to what flute-players, cellists and violinists have to spend to get a good instrument, we guitarists get away cheap. You can get an outstanding student guitar for $500, a good mid-level instrument for $1000 and a concert guitar for $4000 to $10,000. Believe me, that's a bargain. Buying a good cello is like buying a house!
Finally, almost everyone (90% at least) practices too fast! If you want to train your fingers to do what you want them to do precisely, you have to practice pretty slowly. Try half-tempo, or for very difficult passages, one quarter tempo! This is very demanding on your mental concentration, so take frequent breaks. The worst thing you can do is rush through a piece you are learning. That just teaches your fingers to be sloppy. Write "Practice Slowly!!" on a big piece of paper and stick it on your wall.
Now let's hear from someone who obviously practices slowly. I actually had to go down a long way--this is the 24th clip--in YouTube before I found a Villa-Lobos Etude that I was sure was going to be played cleanly enough to make my point. This is Vladimir Mikulka with Etude No. 11 by Villa-Lobos: