A simple query

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

Join Date: Nov 2004
Posts: 68
Reputation: harshchandra is an unknown quantity at this point 
Solved Threads: 1
harshchandra harshchandra is offline Offline
Junior Poster in Training

A simple query

 
0
  #1
Jun 8th, 2005
Is there any way to know the system date automatically using a c program ?
If yes please guide me through some codes !!
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,452
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 251
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: A simple query

 
0
  #2
Jun 8th, 2005
There functions in <time.h> such as time, localtime, and strftime.
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. int main(void)
  5. {
  6. time_t now;
  7. if ( time(&now) != (time_t)(-1) )
  8. {
  9. struct tm *mytime = localtime(&now);
  10. if ( mytime )
  11. {
  12. char buffer [ 32 ];
  13. if ( strftime(buffer, sizeof buffer, "%x", mytime) )
  14. {
  15. printf("buffer = \"%s\"\n", buffer);
  16. }
  17. }
  18. }
  19. return 0;
  20. }
  21.  
  22. /* my output
  23. buffer = "06/08/05"
  24. */
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC