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

Matthew Danish mdanish at andrew.cmu.edu
Tue Mar 11 14:44:21 EST 2003


On Mon, Mar 10, 2003 at 05:41:14PM -0500, Sal Mangiapane wrote:
> Hi all,
> 
> 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

Note that this is the same as: my-C-program < input.file > output.file

> 
> Can I tell the size of the input.file prior to processing?  Or do I
> have to read in the whole input.file and calculate it myself? 

Consider if the "file" being piped in is not a normal file.  ie.

cat /dev/zero | my-C-program

How can you tell the size of this beforehand?

(Sure you can! Infinity!)

If you want to obtain file size information you need to investigate the
stat() family of functions.

-- 
; Matthew Danish <mdanish at andrew.cmu.edu>
; OpenPGP public key: C24B6010 on keyring.debian.org
; Signed or encrypted mail welcome.
; "There is no dark side of the moon really; matter of fact, it's all dark."



More information about the wplug mailing list