As far as text editors, TextEdit will work, but as far as I know, you will constantly run into issues with formatting, spell-check, and other things. If you are guilty of "Which Button Do I Press?" then my first choice is likely not for you.
If you are comfortable using the "Terminal" app, then I suggest using EMACS, (or just emacs). There is a built-in tutorial, and it is a very powerful editor, although for a non command line user it can be daunting, as most of the formatting and editing commands are all control characters (so regular characters are always entered as text). Emacs will do nice highlighting of various language elements just like XCode does. vi is another command line editing tool available on every version of UNIX. Emacs comes with Mac OS/X, as does vi. I have no idea if vi helps with programming as the first thing I do when I start to work on any Unix or Linux box is copy over some version of emacs, so i don't use it except sparingly.
You can also continue to use XCode to edit the source files, as it does a nice job as a WYSIWYG editor and prompts you with help along the way. Just keep a terminal window open to use the command line to compile and link your program, but edit it in XCode and do a SAVE before you switch back to the terminal window.
I also use BBEdit from Bare Bones, and some people like TextWrangler. There are at least a dozen other text editors out there that have features you can enable for programming. Do a google search for Mac OSX text editors and you'll see what I mean.
I advise AGAINST using TextEdit, unless you set the file to "Plain Text". Also, don't use a .txt extension. Use .c, .cc, .ccp, .m, .mm, .js, or whatever the compiler expects to see for a specific language. Binaries will nearly always have a .o extension, and the final binary depends on the language, the linker and what options you provide. The default for c is a.out (or at least it used to be).
You will also want to learn how to use "make", but that is another discussion.
For starters, remember that "man" is your friend. If you want to look up information on Unix, and the command line on the Mac is talking to Unix, aka Darwin. Type "man man" for help getting started with the man command, and "man make" to get started with make. Note at the end of most man pages the section that says "See also", as this tells you about related commands.