I used to work for a large aerospace company, writing automated test software for avionics systems. The hiring managers there were absolutely clueless about anything software-related, so we ended up with way more than our fair share of incompetent programmers. In fact, the incompetent programmers vastly outnumbered the competent ones, which meant that the relatively few competent programmers ended up having to do double-duty - getting their own assignments done while simultaneously having to take responsibility for fixing all the awful code that the incompetent programmers wrote.
Luckily, I managed to fall in with a small niche of very smart, capable programmers. We had a small (4-5 people) group, that went largely unnoticed by management, because we worked on relatively small side projects, whereas the vast majority of the 200 or so programmers at our company were busy working on the avionics flight software. Still, every now and then, when work got scarce, some bean counter manager would reassign one or two programmers to our group, just as a way of keeping them around until more work came in. Over the years, a dozen or so of these "extras" cycled in and out of our group, and most of them were more of a burden than a help.
One guy in particular - let's call him Todd - was constantly writing such terrible code that the rest of us basically had to take turns rewriting his code for him. Every other day or so, he'd ask one of us to help him "troubleshoot" some problem he was having with his code, and whichever one of us got stuck with the dreadful task would follow him back to his cubicle and fix his code for him.
This one time in particular, Todd came looking for help, and the other guys had conveniently slipped off to some meeting somewhere, so I got stuck helping Todd with his code. He'd been given a task to write a small text parser to read data from a log file and dump it into a format that the systems engineers could import into Excel. It was a ridiculously simple log file. One row of data per line, with every line containing the same N data items as the next, with the exception of a roughly 100-line header that contained all sorts of comments and meta-data.
When I asked him what the problem was, he said his parser kept reading the 100-line header every time, even though he'd written it in such a way that he was sure the first 100 lines were being skipped. When I saw his code, I was speechless:
FILE *fp = fopen(argv[1], "r");
char line[100];
int i;
for (i=100;i<99999;i++)
{
if (fgets(line, 100, fp) != NULL)
{
...
}
}
I spent the next 30 minutes trying to explain why fgets doesn't magically know what the value of your loop counter is, and why he shouldn't be using a for loop anyway.