Get feedback on your coding style from someone with more skill and experience.
The way I did it was I got a job where I and a senior programmer cooperated on projects, and he reviewed all the code I checked in. Once in a while he wrote me an email with everything that annoyed or puzzled him about my code. It took a while for me to find a style that both I and he were reasonably comfortable with, and we had some heated debates about some things, but all in all I learned a lot and we parted as friends.
Read books/articles about design patterns, apply different patterns to your problems and see which ones you think are useful in which situations.
Read books/articles about naming conventions and formatting styles. Different communities use different styles. It is generally a good idea to use a style that the people most likely to read your code will recognize.
Some concrete advice on structuring code:
- When you see that some part of your code can be made simpler, do it.
- When you see that some part of your code can be reused, make it a function and reuse it.
- Don't be afraid to change the names of variables and functions if they are bad.
- When you have an idea for something (a struct, function, class, pattern, anything) that can make your life easier, create it and use it.
- Change your mind often. Each time you do, you learn something.
Taking the time to do this will of course slow you down in the beginning. As your code gradually gets more and more elegant, it will get easier to maintain and you will reap the benefits of your work.