Time hour/min/sec

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

Join Date: Sep 2009
Posts: 4
Reputation: grudgemuch is an unknown quantity at this point 
Solved Threads: 0
grudgemuch grudgemuch is offline Offline
Newbie Poster

Time hour/min/sec

 
0
  #1
Sep 30th, 2009
hello. this is my first post in here
im new to programming and im learning C as my first language.

I need help on this problem, i am making a running clock and it prints out in this format:

1:1:11

but i would like to make it look like in this format:

01:01:11

here is my code so far, i am using Turbo C

i really want to google this problem, but i don't know what to search for.
  1. #include <stdio.h>
  2. main()
  3. {
  4. int sec, min, hour;
  5. clrscr();
  6.  
  7. for (hour=0; hour<=24; hour++)
  8. {
  9.  
  10. for (min=0; min<=60; min++)
  11. {
  12. for (sec=0; sec<=60; sec++)
  13. {
  14. printf("%d:%d:%d", hour, min, sec);
  15. delay(100000000);
  16. clrscr();
  17. }
  18. }
  19. }
  20.  
  21.  
  22. getch();
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
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: 254
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Time hour/min/sec

 
2
  #2
Sep 30th, 2009
%d -> %02d
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5. int h = 1, m = 1, s = 1;
  6. printf("%02d:%02d:%02d", h, m, s);
  7. return 0;
  8. }
  9.  
  10. /* my output
  11. 01:01:01
  12. */
"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  
Join Date: Sep 2009
Posts: 4
Reputation: grudgemuch is an unknown quantity at this point 
Solved Threads: 0
grudgemuch grudgemuch is offline Offline
Newbie Poster

Re: Time hour/min/sec

 
0
  #3
Sep 30th, 2009
that works! thanks Dave.

i have a question, what do you call the process of gathering a data from a web page or website, then those gathered data will be used in your program.

for example i want to get the time from a website, then my program will work base on that website's time.

I wanna learn about it but i don't know what its called, so i really can't google it :p is that possible on C?
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,141
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 947
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Time hour/min/sec

 
0
  #4
Oct 1st, 2009
Most people call it HTML Scraping. The programs are called HTML Scrapers. Easy to do with Python, don't know about C.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 4
Reputation: grudgemuch is an unknown quantity at this point 
Solved Threads: 0
grudgemuch grudgemuch is offline Offline
Newbie Poster

Re: Time hour/min/sec

 
0
  #5
Oct 1st, 2009
im not sure if this is called html scraping. here is i wanna do. i hope that this is possible in C.

im not really asking for the code, but i hope someone can point me to the right direction, what programming language is this best to perform, what topic is this? what process is this called (connecting my program to mozilla).

this program will ask me for a keyword that i wanna search for, let's say "Dogs". then after entering the keyword, it will automatically open a browser, let say the Mozilla Firefox, it will open several tabs, one is google, the other one is yahoo, and any web search. then it will input the keyword "Dogs" on those web search's search text box. then it will press search.

it should work like this way:

1. Enter Keyword to search (dogs)
2. Open Mozilla Browser
3. Open Multiple tabs
4. Go to URLs of Google, Yahoo, WebSearch
5. Input the keyword (dogs) to those websearch's search text box
6. then press the "search button"
7. those Google, yahoo will then search for "dogs" at the same time.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,141
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 947
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Time hour/min/sec

 
0
  #6
Oct 1st, 2009
In Python it would be very simple, the url string for the search being the most complicated part ...
  1. # search google with the default web browser (new tab)
  2. # tested with Python 3.1.1
  3.  
  4. import webbrowser
  5.  
  6. search = 'dog'
  7.  
  8. url = "http://www.google.com/search?hl=en&source=hp&q=%s\
  9. &btnG=Google+Search" % search
  10.  
  11. webbrowser.open_new_tab(url)
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,141
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 947
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Time hour/min/sec

 
1
  #7
Oct 3rd, 2009
Okay, I got the message, I will post more stuff in the every so lively C forum!!!!
Last edited by vegaseat; Oct 4th, 2009 at 1:28 pm. Reason: ever
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,553
Reputation: Lardmeister is an unknown quantity at this point 
Solved Threads: 22
Lardmeister's Avatar
Lardmeister Lardmeister is offline Offline
Posting Virtuoso

Re: Time hour/min/sec

 
0
  #8
Oct 3rd, 2009
Actually, your Python program works like a charm!
I upped my sanitary measures, up yours!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 4
Reputation: cryptik is an unknown quantity at this point 
Solved Threads: 0
cryptik cryptik is offline Offline
Newbie Poster
 
0
  #9
Oct 8th, 2009
Originally Posted by Dave Sinkula View Post
%d -> %02d
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5. int h = 1, m = 1, s = 1;
  6. printf("%02d:%02d:%02d", h, m, s);
  7. return 0;
  8. }
  9.  
  10. /* my output
  11. 01:01:01
  12. */
Dave,

I didnt quite get where exactly the clock is running. If this program is executed, then I expect the result always to be /* 01:01:01 */, could you also explain how to run the clock? How to acquire the present time is what I would want to know.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 4
Reputation: cryptik is an unknown quantity at this point 
Solved Threads: 0
cryptik cryptik is offline Offline
Newbie Poster
 
0
  #10
Oct 8th, 2009
Originally Posted by vegaseat View Post
In Python it would be very simple, the url string for the search being the most complicated part ...
  1. # search google with the default web browser (new tab)
  2. # tested with Python 3.1.1
  3.  
  4. import webbrowser
  5.  
  6. search = 'dog'
  7.  
  8. url = "http://www.google.com/search?hl=en&source=hp&q=%s\
  9. &btnG=Google+Search" % search
  10.  
  11. webbrowser.open_new_tab(url)
Bro, could you give the C variation of this one?
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 669 | Replies: 11
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC