Home › Forums › C Programming › How can we know whether a file is read or not
- This topic has 1 reply, 2 voices, and was last updated 14 years, 9 months ago by Chandra3993.
Viewing 1 reply thread
- AuthorPosts
- September 8, 2009 at 11:25 am #2230Archie7891Participant
how can we know whether a particular file is read or not using c programming.
for an example:
the file name = abcd.txt
the status of the file should be 0 if the person has not opened it and it should be changed to 1 after any one reads it
how can we do this
- February 23, 2010 at 7:23 am #3611Chandra3993Participant
Straight way you can not check the file is read or not.
For specific number of days or epoch seconds you can checkHere I have written the program for checking file is read in last 2 days
12345678910111213141516171819202122232425262728293031<br />#include <br />#include <br />#include <br />#include<br />#include<br /><br />main()<br />{<br />struct stat but ;<br />// Here you need to give the file name with absolute path.<br />stat("/home/pavunkumar/secrect",&but );<br />// Here I have calculated the one day epoch time.<br />int limit = 24*60*60;<br />// Getting the last read time of the file.<br />int read = but.st_atime ;<br />int current ;<br />// Getting the current epoch time.<br />current=time ( NULL ) ;<br />// Check file is not open for 2 days.<br />if (((current-read)/limit) >= 2 )<br />{<br />printf ( "file is not read ");<br />}<br />else<br />{<br />printf ( "file is read " ) ;<br />}<br />}<br /><br />
- AuthorPosts
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.