#include #include int main(int argc, char **argv) { FILE *fp, *fp2; char temp[] = "calendar.in"; char temp2[] = "calendar.out"; char *months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; char yearchr[64]; int linje; int centermonth; int monthpos; int centeryear; int yearpos; int teller; int height; int sets; int i,j,k,l; int startday; int year, totaldays; int month; char c, c2; printf("kjører...\n"); if (!(fp = fopen(temp, "r"))) { printf("kan ikke åpne inputfil.\n"); return 1; } fp2 = fopen(temp2, "w"); fscanf(fp, "%i", &sets); for (i = 0; i < sets; ++i) { fprintf(fp2, "+---+----+----+----+----+----+----+----+---+\n"); fprintf(fp2, "| | | | | | | | | |\n"); fprintf(fp2, "| | Mo | Tu | We | Th | Fr | Sa | Su | |\n"); fprintf(fp2, "| | | | | | | | | |\n"); fprintf(fp2, "| +----+----+----+----+----+----+----+ |\n"); fscanf(fp, "%i %i %i %i", &year, &month, &totaldays, &startday); month--; sprintf(yearchr, "%i", year); if ((startday == 0) && (totaldays == 28)) height = 4; else if ((startday == 5) && (totaldays == 31)) height = 6; else if ((startday == 6) && (totaldays >= 30)) height = 6; else height = 5; monthpos = (((height + 1) * 4) / 2) - (strlen(months[month]) / 2) + 1; yearpos = (((height + 1) * 4) / 2) - (strlen(yearchr) / 2) + 1; centeryear =0; centermonth = 0; linje = 6; teller =- startday; for (j = 0; j < height; ++j) { if ((linje >= monthpos)&&(centermonth < strlen(months[month]))) c = months[month][centermonth++]; else c = ' '; if ((linje >= yearpos)&&(centeryear < strlen(yearchr))) c2 = yearchr[centeryear++]; else c2 = ' '; fprintf(fp2, "| %c | | | | | | | | %c |\n", c, c2); linje++; if ((linje >= monthpos)&&(centermonth < strlen(months[month]))) c = months[month][centermonth++]; else c = ' '; fprintf(fp2, "| %c ", c); for (k = 0; k < 7; ++k) { teller++; if ((teller > 0) && (teller <= totaldays)) fprintf(fp2, "| %2i ", teller); else fprintf(fp2, "| "); } if ((linje >= yearpos)&&(centeryear < strlen(yearchr))) c2 = yearchr[centeryear++]; else c2 = ' '; fprintf(fp2, "| %c |\n", c2); linje++; if ((linje >= monthpos)&&(centermonth < strlen(months[month]))) c = months[month][centermonth++]; else c = ' '; if ((linje >= yearpos)&&(centeryear < strlen(yearchr))) c2 = yearchr[centeryear++]; else c2 = ' '; fprintf(fp2, "| %c | | | | | | | | %c |\n", c, c2); linje++; if ((linje >= monthpos)&&(centermonth < strlen(months[month]))) c = months[month][centermonth++]; else c = ' '; if ((linje >= yearpos)&&(centeryear < strlen(yearchr))) c2 = yearchr[centeryear++]; else c2 = ' '; if (j < height-1) fprintf(fp2, "| %c +----+----+----+----+----+----+----+ %c |\n", c, c2); else fprintf(fp2, "+---+----+----+----+----+----+----+----+---+\n"); linje++; } if (i < sets-1) fprintf(fp2, "\n"); } printf("ok.\n"); return 0; }