View Full Version : To find size of a file
ejas_6r
Aug 26, 2007, 10:57 PM
Hi,
I need a help in C++ programming
In program - I want to make empty a log file depending upon its size(eg 10Mb)
retsoksirhc
Aug 26, 2007, 11:08 PM
I'm not too familiar with C++, but I have done PHP... I don't recall a file size function. One way to find it might to just to open the file in append mode, and then get the current file pointer. I *think* youn can do that in C, but like I said, I don't program with it.
asterisk_man
Aug 27, 2007, 12:52 PM
Look up the stat() command.
I think something like this will work.
#include <sys/stat.h>
#include <sys/types.h>
main()
{
struct stat sbuf;
stat("yourfilenamehere",&sbuf);
printf("Your file is %d bytes\n" sbuf.st_size);
}
retsoksirhc
Aug 27, 2007, 12:58 PM
Asterisk man, asterisk man, doing the things an asterisk can, they have a fight, asterisk wins, asterisk man. Bahdubbadubbadubbadubbadubbaduh-bah-bah. - Capuchin
Is he a dot or is he a spec? If he's underwater does he get wet, or does the water get him instead? Asterisk man...