How do you calculate what percentage of a file has been output in C? -
hey guys i'm trying write own 'more' command, problem i'm having how output percentage of file has been read (like original 'more' command). way can think of doing getting number of lines in file , doing calculation calculate percentage every time user enters command ('enter' key display additional single line @ time, 'space' key display 23 lines @ time). there simple way this? if not, have clue how go doing calculation? thanks!
edit: thanks, went ahead , got file size using stat
struct stat st; int filesize; stat(argv[1], &st); filesize = (int)st.st_size;
now need figure out how number of bytes have been read/output far can calculate percentage
if want number of lines in file, need preprocess entire file information.
if want number of bytes in file, can info stat
or fstat
.
c
No comments:
Post a Comment