Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Worst programmer ever?

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?

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

Name: Anonymous 2007-07-26 11:56 ID:Heaven

>>38
explain or gtfo

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;
}

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.

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.

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.

Name: Anonymous 2007-07-26 12:38 ID:DwqUjw26

>>46
And what happens after the while loop?

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;
}

Name: Anonymous 2007-07-26 12:44 ID:SAigVo1L

Also, op is an obvious troll

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

Name: Anonymous 2007-07-26 13:17 ID:4JryrsBt

This thread needs moar flaming.

Name: Anonymous 2007-07-26 13:23 ID:Heaven

lol c
lisp is perfect solution for your problem.
I would know, i read SICP

Name: Anonymous 2007-07-26 13:23 ID:Heaven

>>51
NO U FUCKING IDIOT

Name: Anonymous 2007-07-26 14:50 ID:zbilUcPs

lol bump

Name: Anonymous 2007-07-26 14:52 ID:C8cMOUmF

I'M A GAY WALRUS !!!

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.

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.

Name: Anonymous 2007-07-26 20:03 ID:Heaven

I'm outta here.
oh good :D

Name: Anonymous 2011-05-26 11:16

I fucking hate you,
shiitchan,
you piece of shit

Name: Anonymous 2011-05-26 11:17

[#]shiitchan,
you suck,
and I hate you[/#]

Name: Anonymous 2011-05-26 11:18

fucking shit

Name: Anonymous 2011-05-26 11:18

abc
def
ghi

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List