[wplug] off topic.... C programming question

Eric C. Cooper ecc at cmu.edu
Tue Mar 11 14:53:40 EST 2003


On Mon, Mar 10, 2003 at 05:41:14PM -0500, Sal Mangiapane wrote:
> I am attempting to write a command line C program that will receive
> an input file that it will process in the format:
>     cat input.file | my-C-program > output.file
> Can I tell the size of the input.file prior to processing?

No, because the program has a pipe as its standard input, and you can
only get the size of a regular file.  (You could be typing the input
on the fly, for example).

> Or do I have to read in the whole input.file and calculate it
> myself?

If your program can only read standard input, yes.  But if you can
make your program take the file name as its argument, then you can
stat() the file before processing it.

-- 
Eric C. Cooper          e c c @ c m u . e d u



More information about the wplug mailing list