How Can I Print The File Size In Console??????(i n Bytes)
File Size
Collapse
X
-
-
I don't quite understand how what you are asking this time is different from the discussion you started in this thread
-
Finding the size of the file in C/C++ can be done easily.
Create a file pointer for the input file.
Read character by character and count the characters in a variable.
The total no. of characters in count gives the size of the file in bytes.
Try it.Comment
-
Originally posted by kuttalambalaFinding the size of the file in C/C++ can be done easily.
Create a file pointer for the input file.
Read character by character and count the characters in a variable.
The total no. of characters in count gives the size of the file in bytes.
I suggest you look at the other thread I have linked to in my first reply.Comment
-
Well that rather depends, if you used kuttalambala method and you opened the file in text then the number of characters wont neccessarily be the number of bytes because end of line processing happens which means that the character sequence in the file "\r\n" (carridge return newline) is returned to the program as "\n" so every time there is a new line in the file you count 1 less characters than actually exist in it (for a file with DOS/Windows end of lines).
However ignoring that then basically file byte size and number of characters in the file are basically the same.Comment
-
Why not stick to the old faithful ? :
Code:long FileSize(char* filename) { struct stat stbuf; stat(filename, &stbuf); return stbuf.st_size; }
Code:struct stat /* inode information returned by stat */ { dev_t st_dev; /* device of inode */ ino_t st_ino; /* inode number */ short st_mode; /* mode bits */ short st_nlink; /* number of links to file */ short st_uid; /* owners user id */ short st_gid; /* owners group id */ dev_t st_rdev; /* for special files */ off_t st_size; /* file size in characters */ time_t st_atime; /* time last accessed */ time_t st_mtime; /* time last modified */ time_t st_ctime; /* time originally created */ };
Comment
-
Originally posted by steveski74Why not stick to the old faithful ? :Comment
Comment