944,047 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1738
  • C RSS
Jun 8th, 2005
0

A simple query

Expand Post »
Is there any way to know the system date automatically using a c program ?
If yes please guide me through some codes !!
Similar Threads
Reputation Points: 7
Solved Threads: 1
Junior Poster in Training
harshchandra is offline Offline
68 posts
since Nov 2004
Jun 8th, 2005
0

Re: A simple query

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. */
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: StretchDIBits
Next Thread in C Forum Timeline: how to reverse link list using recurtion





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC