User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 373,577 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,839 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Dec 11th, 2007
Views: 3,193
This program uses snipets from a couple of other programs that I put together in order to make a program that displays the time and date and refreshes the time and date every second. I commented practically every line to explain, as far as I know, what it does. If you know of an easier way to do any of the functions in this program or a more in depth description of what each line is really doing, please comment this and I will fix or change what ever I have to and I'll gladly add your name as a contibutor to this program. ^_^
Last edited : Dec 11th, 2007.
cplusplus Syntax | 5 stars
  1. // This program consists of some program snipets that were pieced together by
  2. // #include<DAN.h>. The result of this compilation is a program that displays
  3. // the time and date and refreshes every second.
  4. #include <time.h> // This includes the time.h header file for getting the
  5. // current time and for waiting
  6. #include <iostream> // This includes the iostream.h header file for input and
  7. // output
  8.  
  9. using namespace std; // Defines the namespace being used
  10.  
  11. void wait ( int seconds ) // The function used to wait
  12. {
  13. clock_t endwait; // All of this just tells
  14. endwait = clock () + seconds * CLOCKS_PER_SEC ; // the program to wait
  15. while (clock() < endwait) {} // however many seconds
  16. // are in the () after
  17. // wait in the main part
  18. // of the program
  19. }
  20.  
  21. int main ()
  22. {
  23. bool on = true; // this bool is just used to repeat the time display
  24. // after the wait and clear screen
  25. while (on != false) // repeats whats in the loop
  26. {
  27. time_t rawtime; // This all just gets
  28. struct tm * timeinfo; // and the time and
  29.  
  30. time ( &rawtime ); // date to be displayed
  31. timeinfo = localtime ( &rawtime ); // in the next line
  32. cout << "Current local time and date: " << asctime (timeinfo);
  33. // the line above displays the time and date
  34.  
  35. wait (1); // waits 1 second
  36. system("cls"); // clears the screen for the next display
  37. }
  38. return 0;
  39. }
Comments (Newest First)
stephen84s | Junior Poster | 15 Days Ago
To get this code to work on Linux, just replace the line system("cls"); with system("clear") .
BTW gotta say a very nice and useful piece of code.
mohamed yousef | Newbie Poster | Feb 13th, 2008
first i'd like to thank you vey this powerful code you have made but
iam tryinh\g to do this by using the structure this is required from me to do the time by structures and i face a problem taht the counting of seconds is very fast what can i do to make delay
and also ther is some thing if i want to use the function window() for good interface what should i include for the header file
Samlouel | Newbie Poster | Jan 9th, 2008
can you explain whats the function Of #include <DAN.h>?
this kind of syntax are not in my computer library, how can i achieve it?
can i download this syntax header?
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 7:49 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC