I am trying to assemble my C calendar program to make it looks like the real Unix program. Specifically, I am trying to make the first 3 months displaying like this:
2017
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7 1 2 3 4 1 2 3 4
8 9 10 11 12 13 14 5 6 7 8 9 10 11 5 6 7 8 9 10 11
15 16 17 18 19 20 21 12 13 14 15 16 17 18 12 13 14 15 16 17 18
22 23 24 25 26 27 28 19 20 21 22 23 24 25 19 20 21 22 23 24 25
29 30 31 26 27 28 26 27 28 29 30 31
Here is my code, it's a draft and I will try to reduce it later. I am doing the printing line-by-line method
void printJanFebMar(int year)
{
printf(" %d\n",year);
//print months from January to March
printf(" January February March\n");
for(int i = 0;i<3;i++){
printf(" Su Mo Tu We Th Fr Sa ");
}
printf("\n");
//January, February and March
//first line of days...
int record1 = 0;
int record2 = 0;
int record3 = 0;
for(int k = 0;k<findStartDateInMonth(1,year);k++){
printf(" ");
}
for(int j = 1;j<=daysInMonth[1];j++){
printf("%3d",j);
if((j+findStartDateInMonth(1,year)) % 7 == 0){
break;
record1 = j + findStartDateInMonth(1,year) +1;
printf("%d",record1);
}
}
printf(" ");
for(int k = 0;k<findStartDateInMonth(2,year);k++){
printf(" ");
}
for(int j = 1;j<=daysInMonth[2];j++){
printf("%3d",j);
if((j+findStartDateInMonth(2,year)) % 7 == 0){
break;
record2 = j + findStartDateInMonth(2,year) +1;
printf("%d",record2);
}
}
printf(" ");
for(int k = 0;k<findStartDateInMonth(3,year);k++){
printf(" ");
}
for(int j = 1;j<=daysInMonth[3];j++){
printf("%3d",j);
if((j+findStartDateInMonth(3,year)) % 7 == 0){
break;
record3 = j + findStartDateInMonth(3,year) +1;
printf("%d",record3);
}
}
printf("\n");
//second line
/*
for(int i = record1;i<record1+7;i++){
printf("%3d",i);
}
printf(" ");
for(int i = record2;i<record2+7;i++){
printf("%3d",i);
}
for(int i = record2;i<record2+7;i++){
printf("%3d",i);
}
*/
printf("\n");
It prints out the first line for the days, however, when I try to save the value of the day that will be in the newline for future printf statements, the values are not printed out as shown in the
printf("%d",record1);
Here is the current output of my program:
2017
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7 1 2 3 4 1 2 3 4
What is my error in assigning values to record1,record2 and record3 and how would I fix it.
I'm sorry for the long post and I would really appreciate any help