I wrote a C# syntax highlighter using regex and a mini "state machine" (a few if statements) here, it could be adapted for C, C++ and Java fairly easily. It produces the inline styles by default and a pre tag.
The source is there in C#.
(Cross pollination answer)