I'm making a program that you input the month and year, and it creates a calender for that month of that year. This is my largest project yet, and I broke it up into several source files.
cal.c
#include "cal.h"
#include <stdio.h>
main() {
int month, year;
scanf("%d %d", &month, &year);
if (yearstart(year) == 0)
printf("error: year (%d) is lower then 1989:\n\tprogram will continue, but may give incorrect results\n\a", year);
if (yearend(year) == 0)
printf("error: year (%d) is larger then 2017:\n\tprogram will continue, but may give incorrect results\n\a", year);
if (monthstart(month) == 0) {
printf("error: month (%d) is lower then 1:\n\tthis error makes the program unusable; program will end now\n\a", month);
return 0;
}
if (monthend(month) == 0) {
printf("error: month (%d) is higher then 12:\n\tthis error makes the program unusable; program will end now\n\a", month);
return 0;
}
monthprint(month);
printf("\n");
}
cal.h
#define YEARSTART 1989
#define YEAREND 2017
#define MONTHSTART 1
#define MONTHEND 12
#define JANNUMBER 1
#define FEBNUMBER 2
#define MARNUMBER 3
#define APRNUMBER 4
#define MAYNUMBER 5
#define JUNNUMBER 6
#define JULNUMBER 7
#define AUGNUMBER 8
#define SEPNUMBER 9
#define OCTNUMBER 10
#define NOVNUMBER 11
#define DECNUMBER 12
int yearstart(int);
int yearend(int);
int monthstart(int);
int monthend(int);
void monthprint(int);
error.c
#include "cal.h"
#include <stdio.h>
int yearstart(int year) {
return (year < YEARSTART) ? 0 : 1;
}
int yearend(int year) {
return (year > YEAREND) ? 0 : 1;
}
int monthstart(int month) {
return (month < MONTHSTART) ? 0 : 1;
}
int monthend(int month) {
return (month > MONTHEND) ? 0 : 1;
}
print.c
#include "cal.c"
#include <stdio.h>
const char jan[] = "January";
const char feb[] = "Febuary";
const char mar[] = "March";
const char apr[] = "April";
const char may[] = "May";
const char jun[] = "June";
const char jul[] = "July";
const char aug[] = "August";
const char sep[] = "September";
const char oct[] = "October";
const char nov[] = "November";
const char dec[] = "December";
void monthprint(int month) {
switch(month) {
case JANNUMBER:
printf("%s", jan);
break;
case FEBNUMBER:
printf("%s", feb);
break;
case MARNUMBER:
printf("%s", mar);
break;
case APRNUMBER:
printf("%s", apr);
break;
case MAYNUMBER:
printf("%s", may);
break;
case JUNNUMBER:
printf("%s", jun);
break;
case JULNUMBER:
printf("%s", jul);
break;
case AUGNUMBER:
printf("%s", aug);
break;
case SEPNUMBER:
printf("%s", sep);
break;
case OCTNUMBER:
printf("%s", oct);
break;
case NOVNUMBER:
printf("%s", nov);
break;
case DECNUMBER:
printf("%s", dec);
break;
defualt:
printf("fatal error\n\a");
break;
}
}
And here is my compile method:
~/c/etc/calender $ ls
cal.c cal.h error.c print.c
~/c/etc/calender $ gcc -o cal cal.c cal.h error.c print.c
/tmp/ccU3dRmi.o: In function `main':print.c:(.text+0x0): multiple definition of `main'
/tmp/ccscxcaw.o:cal.c:(.text+0x0): first defined here
collect2: ld returned 1 exit status
There is no main in print.c...is there?