Solved

time/day and C only

Posted on 2001-06-30
2
187 Views
Last Modified: 2010-04-21

I want to make a greeting, in Linux (C program only)like

if hour is > 18PM and < 22PM
print "good evening, today is Wednesday. in year 2001 has 200 days remaining, time now is %s", time$);

if hour is > 4AM and <8AM
print "good morning, today is Friday. in year 2001 has 172 days remaining, time now is %s", time$);

0
Comment
Question by:16bits
2 Comments
 
LVL 8

Accepted Solution

by:
mnashadka earned 50 total points
Comment Utility
Try something like:
time_t now;
struct tm *time_struct;
char day_str[20];
char time_str[20];

now = time(NULL);
time_struct = mktime(&now);

strftime(day_str, 20, "%a", time_struct);
strftime(time_str, 20, "%H:%M:%S", time_struct);

if(time_struct->
tm_hour > 18 && time_struct->tm_hour < 22)
{
  printf("Good evening, today is %s in year %d, it is the %d day of the year, time now is %s", day_str, time_struct->tm_year, time_struct->yday, time_str);
}
else if(time_struct->
tm_hour > 4 && time_struct->
tm_hour < 8)
{
  printf("Good morning, today is %s in year %d, it is the %d day of the year, time now is %s", day_str, time_struct->tm_year, time_struct->yday, time_str);
}

Note, this doesn't give you the number of days remaing.  To do this, you need to figure out the number of days in the year and subtract time_struct->yday from that.  Hope this helps.    
0
 

Author Comment

by:16bits
Comment Utility
it actually helps a lot, thank you!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now