File modification time as an int

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2009
Posts: 23
Reputation: raigs is an unknown quantity at this point 
Solved Threads: 0
raigs raigs is offline Offline
Newbie Poster

File modification time as an int

 
0
  #1
Oct 30th, 2009
How can I return the file modification time as an int (UNIX epoch)?
  1. #include <time.h>
  2. #include <sys/stat.h>
  3.  
  4. int *FILEMOD(char *FILENAME)
  5. {
  6. struct stat ATTRIBUTES;
  7. time_t MTIME;
  8.  
  9. stat(FILENAME, &ATTRIBUTES);
  10. MTIME = ATTRIBUTES.st_mtime;
  11.  
  12. return MTIME;
  13. }
  14.  
  15. int main(void)
  16. {
  17. printf("%i",FILEMOD("file.txt"));
  18.  
  19. return 0;
  20. }
gcc errors:
filemod.c: In function ‘FILEMOD’:
mod.c:14: warning: return makes pointer from integer without a cast
mod.c: In function ‘main’:
mod.c:19: warning: incompatible implicit declaration of built-in function ‘printf’
Last edited by raigs; Oct 30th, 2009 at 3:21 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 33
Reputation: SVR is an unknown quantity at this point 
Solved Threads: 4
SVR SVR is offline Offline
Light Poster
 
0
  #2
34 Days Ago
Just cast the return, time_t is equivalent to int for 32 bit OS.

  1. return (int) MTIME;

To fix the printf warning include stdio.h
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC