Created
April 12, 2012 19:04
-
-
Save semahawk/2370170 to your computer and use it in GitHub Desktop.
Dni do końca roku
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.o | |
dni-do-konca |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* dni-do-konca.c | |
* | |
* Copyleft: (c) 2012 by Szymon Urbaś <[email protected]> | |
* | |
* License: the MIT license | |
* | |
* About: | |
* | |
* The program prints how many days there are to the end of school year. | |
* | |
* Compile: | |
* | |
* make | |
* | |
*/ | |
#include <stdio.h> | |
#include <time.h> | |
int main(void){ | |
time_t current_year, raw_time; | |
int day, month, year; | |
struct tm t, *ct; | |
time(¤t_year); | |
localtime_r(¤t_year, &t); | |
if (t.tm_mon == 5 || t.tm_mon == 6){ | |
printf("As Billy Joe would say.. HOLIDAY!\n"); | |
return 0; | |
} | |
printf("End of school year: (dd/mm/yyyy) "); | |
scanf("%d/%d/%d", &day, &month, &year); | |
time(&raw_time); | |
ct = localtime(&raw_time); | |
ct->tm_mday = day; | |
ct->tm_mon = month - 1; | |
ct->tm_year = year - 1900; | |
mktime(ct); | |
if (ct->tm_yday - t.tm_yday > 0){ | |
printf("There are %d days left to the end of school!\n", (ct->tm_yday + 1) - (t.tm_yday + 1)); | |
} else if (ct->tm_yday - t.tm_yday == 0){ | |
printf("Yay, it's today!\n"); | |
} else { | |
printf("Hey, you missed the end of school..\n"); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# dni-do-konca | |
# | |
# Copyleft: (c) 2012 by Szymon Urbaś <[email protected]> | |
# | |
# License: the MIT license | |
# | |
CXX = gcc | |
CXXFLAGS = -W -Wall -std=c99 | |
OBJS = dni-do-konca.o | |
dni-do-konca: $(OBJS) | |
$(CXX) $(OBJS) -o $@ | |
dni-do-konca.o: dni-do-konca.c | |
$(CXX) $(CXXFLAGS) -c dni-do-konca.c | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment