[QUOTE=robwhit;704316]
>But it would make the function cleaner.
I won't need to look at the function again.
>but suppose that I wanted to make 5 files that had that content? How would I do that? the function would exit every time.
Just uses a different file name.
>And what error would the compiler not be able to catch with a snippet that small? Would you really not be able to see it with just a casual glance over the code?
Don't understand what you are saying.
>Fast access from what to what?since the buffer is in memory, the only way that you would need disk I/O to access the buffer is if the buffer was in swap space, which would be more likely with a larger buffer.
Fast access to the data which was in the data file.
If you have not already read in the whole file you may require further disk reads when
you want to access a different apart of the file. That is very slow.
The quickest way is to read the whole file in at the start then no further disk IO
should be needed.
>The time it takes to increment a counter is microscopic compared to the time it takes for disk i/o.I think that if a function does one thing, it's simpler than if it does two.
It's stil time and the poinit is I don't need to write the code for the counter, which takes time and makes the code longer.
The function may be more complicated but you only write it once and then you can forget
about it. However you still have to put the error handling into the main program which
makes the main program look more compliceted.
When you have put the function into a hundred different programs you will be wishing you had put the error handling in the function, otherwise you will have to write the error handling a hundred times. You will probably make a mistake writing it on a few occasions
too which will consume even more time.
Sometimes you might forget to even write the error handling so your program will
fail and you won't know why.
That won't be a lot of fun, you could spend hours debugging it.
I only need to get it right once. You have to get it right every time.
You might forget the error code, was it 1 or -1 which was an error?
Who knows? I don't need to worry about that.