You need to read as many bytes as will fit in the buffer. Right now, you don't have a buffer yet, all you got is a pointer to a buffer. That isn't initialized to anything. Chicken-and-egg, you therefore don't know how many bytes to read either.

That's what I have on my guide. It specifies 100 chars, If you don't know how many chars the file has what would you write on the calloc?
–
andandandandOct 5 '10 at 18:22

1

You could normally benefit from a bigger buffer, but 100 will do. Just use a loop to read a piece into that buffer, and write that piece out to stdout (read() will tell you how much it actually filled into the buffer, so don't write more than that on each loop)
–
nosOct 5 '10 at 18:23

There is usually no need to read the entire file in one gulp. Choosing a buffer size that is the same or a multiple of the host operating system's memory page size is a good way to go. 1 or 2 X the page size is probably good enough.

Using buffers that are too big can actually cause your program to run worse because they put pressure on the virtual memory system and can cause paging.