Skip to content

Instantly share code, notes, and snippets.

@semahawk
Created April 12, 2012 19:04
Show Gist options
  • Save semahawk/2370170 to your computer and use it in GitHub Desktop.
Save semahawk/2370170 to your computer and use it in GitHub Desktop.
Dni do końca roku
*.o
dni-do-konca
/*
* dni-do-konca.c
*
* Copyleft: (c) 2012 by Szymon Urbaś <urbas@hush.ai>
*
* 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(&current_year);
localtime_r(&current_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;
}
#
# dni-do-konca
#
# Copyleft: (c) 2012 by Szymon Urbaś <urbas@hush.ai>
#
# 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