cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Check for empty file.
Check for empty file.
Oct 7, 2009 at 11:43pm UTC
IamScaredOfTrees
(14)
I need to check if my text file is empty. If so, I exit the program. But, I need to do this without reading anything into a buffer as to not lose any text if it is not empty.
My code is basically:
1
2
3
4
while
(get_line(input) >=0){ blah blah blah } prinf(stuff)
So I can't just say:
1
2
if
(input ==EOF) exit(1);
because after I read through the file I need to print(not during). And I have to exit or my print section will seg-fault.
Last edited on
Oct 7, 2009 at 11:47pm UTC
Oct 7, 2009 at 11:56pm UTC
kbw
(9488)
Check the size with stat()
Oct 8, 2009 at 12:00am UTC
IamScaredOfTrees
(14)
Thanks a bunch.
Topic archived. No new replies allowed.