Do you know what fgetc() returns if EOF is reached?
What if iNum is negative?
Do not cast your mallocs
If you're going to store the return value of fread, better error check it.
int vCopyFile(FILE *fp, FILE *dest, int nsize) {
int c;
int n = 0;
if(fp == NULL || dest == NULL)
return -1;
for(c = getc(fp); c != EOF && n < nsize;
n++, c = getc(fp))
putc(c, fp);
>>3 here
add to that you forgot to check the return value of malloc, and i lold @ the void cast
Name:
Anonymous2007-07-26 10:22 ID:HamNtPBW
Windows needs to be told it's in binary mode, try the _setmode function
Name:
Anonymous2007-07-26 10:25 ID:kmDLYctK
Yes, you possibly are the worst programmer, ever.
Your two functions go from one extreme to another. In one, you process the stream one byte at a time, while in the other, you process the entire stream in one shot.
The first is unnecessarily slow. The second is unnecessarily wasteful on memory.
Also, just for fun, run your second function on a 5 GB stream and see what happens. You'll shit bricks when you see it.
Also, you fucking forgot to free the allocated memory like a jackass.
Also, reinventing the wheel, etc. library functions, motherfucker, do you use them?
>>6
oh now i understood why you said a 5+GB stream
i though you where talking about the file IO operations, but apparently you where refering to the dynamic allocation part
>>14
We pointed every fucking thing that was wrong in his code you fucking idiot.
probably troll but these days it's hard to tell.
Name:
Anonymous2007-07-26 10:51 ID:HamNtPBW
int main(int argc, char *argv[])
{
unsigned char buffer[1048576];
int bytes_read= 0;
int i;
#ifdef WINDOWS
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
#endif
do {
bytes_read = fread(buffer, 1, sizeof(buffer), stdin);
/* TODO: insert code here to manipulate buffer, if needed */
fwrite(buffer, bytes_read, 1, stdout);
} while(bytes_read > 0 || !feof(stdin));
return 0;
}
Name:
Anonymous2007-07-26 10:56 ID:4JryrsBt
>>3
Thanks for your correction, but it still doesn't work.
After copying 264 bytes, the function returns 264 as it should,
but ftell() gives 265 for fp and 264 for dest.
unsigned char buffer[1048576];
fail int bytes_read = 0;
fread returns size_t which is an object of unsigned type.
and why do you set it to 0?
size_t bytes;
while(bytes = fread(buffer, 1, sizeof(buffer), stdin)) {
if(feof(stdin)) break;
fwrite(buffer, bytes_read, 1, stdout);
}
>>1
Why do you beginners make such a mess with types, and, in particular, feel like you should throw a cast in every other line for good luck? Approximately 40% of the typecasts or type converstions I see in code I read are absolutely unnecessary.
Bastardized Hungarian notation (or any Hungarian notation) makes me want to cry.
It's so unnecessary, ugly, hard to read, and reeks of the Win32 API.
Name:
Anonymous2007-07-26 11:18 ID:Z28fIwsy
you're doing it wrong. here's how you do it
Prelude Data.ByteString.Lazy> :t \f1 f2 n -> hGet f1 n >>= hPut f2
\f1 f2 n -> hGet f1 n >>= hPut f2 :: GHC.IOBase.Handle -> GHC.IOBase.Handle -> Int -> IO ()
>>29
WHAT A FUCKIGN IDIOT
NOW THAT DESERVES TEH ANGERED EXPERT PROGRAMMER COPYPASTA ... buf = new ...
I SEE NO del buf IN YOUR CODE, NO I DON'T.
AND YOUR CODE FUCKING SUCKS ANYWAY, YOU DON'T CHECK WHAT new RETURNS AND ... OH MY GOD YOU KNOW WHAT? FUCK THAT. YOUR CODE IS OVERBLOATED AND VERY RETARDED.
I MEAN IT. VERY.
That makes me think, what we really need is a BBCode RFC. I would crack one off to that thrice daily.
Name:
Anonymous2007-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.