Take the 2-minute tour ×

I'm trying to get the size of a file from the commandline in C using argv. I'm not too familiar with file i/o in C, so any pointers would be greatly appreciated. Thanks.

share|improve this question
You should try Googling things like "C argv" or "C argv parsing". Results such as these appear: cplusplus.com/forum/articles/13355 –  Josh Apr 11 '12 at 6:11
whathaveyoutried.com –  vsz Apr 11 '12 at 6:12
0% accept rate. :-( –  Kyle Jones Apr 11 '12 at 6:16
Welcome to StackOverflow. Please note that the preferred way of saying 'thanks' around here is by up-voting good questions and helpful answers (once you have enough reputation to do so), and by accepting the most helpful answer to any question you ask (which also gives you a small boost to your reputation). Please see the FAQ and especially How do I ask questions here? –  Jonathan Leffler Apr 11 '12 at 6:16
man stat or search MSDN for GetFileSizeEx. –  asveikau Apr 11 '12 at 6:17
show 1 more comment

closed as not a real question by casperOne Apr 12 '12 at 12:32


1 Answer

You've not stated the platform, but your C program is given an argument list when it is started, and the file names are strings. The POSIX function you'd probably use is stat(); it takes a pointer to a struct stat and will put the file's size into the st_size member of the structure.

The answer may be different on Windows; the POSIX subsystem will provide a stat() workalike (probably named _stat()), but there'll also be a native interface.

share|improve this answer
add comment
