Read this http://cboard.cprogramming.com/c-programming/88495-development-process.html
Then start again with an empty file which you build up SLOWLY with lots of compiling and testing as you go.