Sometimes a Four Just Isn't a Four
onWow. I love The Daily WTF, and looking back at some of my code, I've written some WOEs myself. (WOE = What On Earth). So, I'd like to share them. Because they're funny. Yes.
for (i=0;i<toParse.length();i++) { if ((toParse.substr(i, 1) != " ") && (toParse.substr(i, 1) != "4") && (toParse.substr(i, 1) != "\n")) { cout << endl << endl << "ERROR: Unrecognized character in line " << lineNum << ":" << endl; cout << "\t" << curline; endProgram(); } } int j = 0; i = 0; if (toParse.length() > 0) { while (toParse.length() != 0) { if ((toParse.substr(i, 1) == " ") || (toParse.substr(i, 1) == "\n")) { if (i == 0) { toParse = toParse.substr(1); i = -1; } else { string2int((char*)toParse.substr(0, i).c_str(),paras[j]); j++; toParse = toParse.substr(i + 1); i = -1; } } i++; }
If you haven't gotten it yet, here's the explanation. The program first verifies that the string
toParse
does not contain any non-4s, non-dashes and non-spaces. Then it examines each character and if it is not a dash or a space, it converts the character from an integer to a string. This is absolutely ridiculous as the only value that character could be at that point would be a 4.This WOE has been taken from lines 43-72 of
singlefour.cpp
of the singlefour project. This code was introduced in revision 7 and fixed in revision 26.
Comments