- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
No shell script, vi only:
vi merchant.cfg
3049iN<ESC>AY<ESC>:wq
and you're done.
Admin
Why not just have a bit field in the merchant table with 1 if they're "special" and null or zero if they're not?
Admin
Despite the other two major WTFs in this code, the first thing I thought was "if the file exists but has no bytes, this function leaves lingering filehandles all over the place".
Admin
He could be working in an environment there is a DBA who owns and runs the database server and this legend has to write his app around it. He asks the DBA to add a field for this and the DBA refuses. So, legend comes up with this work-around.
But if you're going to do a bad thing, at least do it well.
Admin
Admin
Ha ha - the real "WTF" is that this code works reliably well, when when the MerchantID is '9999'. Except when it goes into production. Most C/C++ environments will auto zero out array's for DEBUG mode, and not do the same for RELEASE code. This is the evil that we deal with on a daily basis here at my job [MSVC6]
So, I can see the endless finger-pointing on this one. "The app crashes randomly in production when we call your function"
"Bah - look it works perfectly well. Let me demonstrate every possible merchant ID - nothing crashes. See? Now go away Java-kid and figure out what you did wrong"
Admin
FYI: it will never read 10000 bytes unless the file is that big.
So you don't see the WTF huh?....reserving tons of memeory on the stack for no reason, open/read/close the same file over and over (several hundred thousand times), useless variables like ab=0, blindly indexing the array with the passed merchnum... I could go on.
Let me guess, you are Scott, aren't you?
- Joe D
Admin
Guess you don't use fread() that much, eh?
RETURN VALUE fread and fwrite return the number of items successfully read or written (i.e., not the number of characters). If an error occurs, or the end-of-file is reached, the return value is a short item count (or zero).
Noob.
Admin
Original guy also flip flopped his sz and nmemb fields. Looks like drunk code. I'd have to wonder if the input is really only 23 bytes or else it would fail all the time.
Admin
Or better yet just make it a struct field that is init'd appropriately upon load. Small file changes, reload. It's obviously not a mission critical app - because that function isn't doing anything but creating dangling file handles.
Admin
Wow,
When I grow up I'm gonna be a legend in my own mind too.
Admin
Biometryka Biometria
Admin
not really ...
as Alex wrote : only 2% of the merchants are "special" - I strongly believe that all special merchants are covered in the first 23 merchants - why then bother with writing thousands of "N"s .. 23 bytes are fully sufficient
all other array-indices will not yield "Y" and as the arraybuffer is reserved for 10000 merchants, the code works flawless ....
a brillant solution - and very economical ...