Worst programmer ever?
1
Name:
Anonymous
2007-07-26 10:03
ID:4JryrsBt
So I wrote a function to copy a specified number of bytes
from one stream to another:
void vCopyFile(FILE *fIn, FILE *fOut, int iNum) {
while (iNum--)
(void)fputc(fgetc(fIn), fOut);
}
I was told the following:
20:34:53 < dinesh> wow
20:35:00 < dinesh> probably one of the worst function i ever saw
So I changed it to this:
void vCopyFile(FILE *fIn, FILE *fOut, int iNum) {
char *cBuf = (char*)malloc(iNum);
int iRead;
iRead = fread(cBuf, 1, iNum, fIn);
fwrite(cBuf, 1, iRead, fOut);
}
Both functions work on Linux but seem to skip bytes when
crosscompiled with mingw32-gcc or visual studio.
What am I doing wrong?
41
Name:
Anonymous
2007-07-26 11:52
ID:xXKsepsE
>>35
I bet you're the type of guy who wanks off to prime-numbered RFCs every night.
FUCKING LOL'D
42
Name:
Anonymous
2007-07-26 11:56
ID:Heaven
43
Name:
Anonymous
2007-07-26 12:08
ID:DwqUjw26
#include <stdio.h>
#include <stddef.h>
int EXPERT_copy_file (FILE* in, FILE* out, size_t n)
{
char buf[BUFSIZ];
size_t nread;
while (n > sizeof(buf)) {
nread = fread(buf, 1, sizeof(buf), in);
if (nread < sizeof(buf))
return -1;
if (fwrite(buf, 1, nread, out) < nread)
return -1;
/* lol rollback */
n -= sizeof(buf);
}
nread = fread(buf, 1, n, in);
if (nread < n)
return -1;
if (fwrite(buf, 1, nread, out) < nread)
return -1;
return 0;
}
44
Name:
Anonymous
2007-07-26 12:11
ID:Heaven
>>43
if (nread < sizeof(buf))
return -1;
fail, check for ferror.
dude, i never knew we have so many C n00bs here.
45
Name:
Anonymous
2007-07-26 12:23
ID:DwqUjw26
>>44
This is the EXPERT version, only to be compiled with the finest optimization flags. Requesting more than available is not tolerated.
46
Name:
Anonymous
2007-07-26 12:25
ID:Heaven
>>45
you just dont get it eh?
if the size of the file is less than BUFSIZ or not a multiply of BUFSIZ your function will fail.
maybe in v2 man.
47
Name:
Anonymous
2007-07-26 12:38
ID:DwqUjw26
>>46
And what happens after the while loop?
48
Name:
Anonymous
2007-07-26 12:43
ID:SAigVo1L
int EXPERT_copy_file(FILE *i,FILE *o,size_t n){
char buf[0x400];
size_t read,wrote,to_read=sizeof(buf);
if(to_read<n)
to_read=n;
while((read=fread(buf,1,to_read,i))){
if(read!=to_read)
return -1;
if ((wrote=fwrite(buf,1,read,o))!=read)
return -1;
n-=read;
if(to_read<n)
to_read=n;
}
return 0;
}
49
Name:
Anonymous
2007-07-26 12:44
ID:SAigVo1L
Also, op is an obvious troll
50
Name:
Anonymous
2007-07-26 12:48
ID:Heaven
>>47
WHAT HAPPENDS AFTER THE while LOOP? YOU STILL DO THE IF CHECK AND return -1 YOU FAGGOT
SAGE
51
Name:
Anonymous
2007-07-26 13:17
ID:4JryrsBt
This thread needs moar flaming.
52
Name:
Anonymous
2007-07-26 13:23
ID:Heaven
lol c
lisp is perfect solution for your problem.
I would know, i read SICP
53
Name:
Anonymous
2007-07-26 13:23
ID:Heaven
54
Name:
Anonymous
2007-07-26 14:50
ID:zbilUcPs
lol bump
55
Name:
Anonymous
2007-07-26 14:52
ID:C8cMOUmF
I'M A GAY WALRUS !!!
56
Name:
Anonymous
2007-07-26 16:12
ID:3c8igOW3
This is the funniest thread I've read for ages.
Masturbating to prime-numbered RFCs, indeed!
That makes me think, what we really need is a BBCode RFC. I would crack one off to that thrice daily.
57
Name:
Anonymous
2007-07-26 18:20
ID:f87SIMjE
You are all such stupid faggots. You just can't get one thread right, do you? Stupid pieces of shits, I came from Reddit after some interesting articles but this is just too much; I've been reading the board a bit and it's all pages and pages of bullshit, you fucking faggots I'm outta here.
58
Name:
Anonymous
2007-07-26 20:03
ID:Heaven
I'm outta here.
oh good :D
60
Name:
Anonymous
2011-05-26 11:16
I fucking hate you,
shiitchan,
you piece of shit
61
Name:
Anonymous
2011-05-26 11:17
[#]shiitchan,
you suck,
and I hate you[/#]
62
Name:
Anonymous
2011-05-26 11:18
fucking shit
63
Name:
Anonymous
2011-05-26 11:18
abc
def
ghi
Newer Posts