This is for an assignment I posted a couple of days ago. I have successfully completed the Void setCal part. I can also get the programme to look as it should, but replacing the line fprintf.....(in the writeHead fn) with printf("%......), and by simply using printf with each individual line of char*head, and char days[], printing each of them above the months, as they are printed in (iterating) groups of three. Unfortunately, that is not what the assignment wants for writeCal. It wants somehow to print char*head and char days to disc and then to screen. The assignment gives an example of, for char *strings[] = {"one", "two", "three");
fprintf(myfile, "%s", strings[2]; outputting three to myfile. I presume then that I would use the same principle with char*head[]. But how do I then print char head[0], char head[1] etc to my computer screen? And how do I do this first of all with void writeHead - as this prinnts my heading on screen. I'm just learning, so I would appreciate some help on this. I realize you may consider the answer really easy, but I don't at this stage know how to go about this.

// cal.c - calendar for 1583 on
#include <stdio.h>
#include <string.h>

FILE *myfile;

typedef int calendar[20][21];

int getYear(char []);
int firstDay(int);
void setCal(int, calendar);
void writeHead(int);
void writeCal(calendar);

int main(void)
{
calendar cal = { {0} };
char calName[] = " calendar.doc";
int yr;

yr = getYear(calName);
setCal(yr, cal);
myfile = fopen(calName, "w");
writeHead(yr);
writeCal(cal);
fclose(myfile);
printf("\nFinished\n");
return 0;
}

int getYear(char calName[])
{
char dummy[80];
int cnt, yr, y;

do
{
printf("year(dddd): ");
cnt = scanf("%d", &yr);
gets(dummy);
if (cnt == 1)
if (yr > 1582)
break;
else
printf("Year must be > 1582\n");
else
printf("Non-numeric data\n");
} while (1);
y = yr;
calName[3] = y % 10 + '0';
y /= 10;
calName[2] = y % 10 + '0';
y /= 10;
calName[1] = y % 10 + '0';
calName[0] = y / 10 + '0';
return yr;
}

int firstDay(int yr) // using Zeller's congruence
{
int a, b, c, d, dd = 1, m, mm = 1;

if (mm < 3)
yr--;
m = (mm + 9) % 12 + 1;
a = (int)(2.6 * m - 0.2);
b = yr % 100;
c = yr / 100;
d = (a + dd + b + b / 4 + c / 4 - 2 * c) % 7;
if (d < 0)
d += 7;
return d;
}

void setCal(int yr, calendar cal) // prepare calendar for year yr
{
int mondays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int day, month, row, col, startCol, startRow;

// you are to complete this
}

void writeHead(int yr)
{
int i, spaces, width, y1, y2, y3, y4;
char *num[10][8] = {
{" @@@ ", "@ @ ", "@ @ ", "@ @ ", "@ @ ", "@ @ ", " @@@ ", "======"},
{" @ " , "@@ " , " @ " , " @ " , " @ " , " @ " , "@@@ " , "====" },
{" @@@ ", "@ @ ", " @ ", " @ ", " @ ", " @ ", "@@@@@ ", "======"},
{" @@@ ", "@ @ ", " @ ", " @@@ ", " @ ", "@ @ ", " @@@ ", "======"},
{" @ ", " @@ ", " @ @ ", "@ @ ", "@@@@@ ", " @ ", " @ ", "======"},
{"@@@@@ ", "@ ", "@ ", "@@@@ ", " @ ", "@ @ ", " @@@ ", "======"},
{" @@@ ", "@ ", "@ ", "@@@@ ", "@ @ ", "@ @ ", " @@@ ", "======"},
{"@@@@@ ", " @ ", " @ ", " @ ", " @ ", "@ ", "@ ", "======"},
{" @@@ ", "@ @ ", "@ @ ", " @@@ ", "@ @ ", "@ @ ", " @@@ ", "======"},
{" @@@ ", "@ @ ", "@ @ ", " @@@@ ", " @ ", " @ ", " @@@ ", "======"}};

y4 = yr % 10;
yr /= 10;
y3 = yr % 10;
yr /= 10;
y2 = yr % 10;
y1 = yr / 10;
spaces = (int)(strlen(num[y1][0]) + strlen(num[y2][0])
+ strlen(num[y3][0]) + strlen(num[y4][0]));
spaces = 3 + (70 - spaces) / 2;
width = (int)strlen(num[y4][0]) - 1;
for (i = 0; i < 8; i++)
fprintf(myfile, "%*c%s%s%s%.*s\n", spaces, ' ', num[y1][i], num[y2][i],
num[y3][i], width, num[y4][i]);
}

void writeCal(calendar cal)
{
char *head[] = {"JANUARY FEBRUARY MARCH",
"APRIL MAY JUNE",
"JULY AUGUST SEPTEMBER",
"OCTOBER NOVEMBER DECEMBER"};
char days[] = " S M T W Th F S S M T W Th F S S M T W Th F S";
int i, row, col;

// you are to complete this
}