main(){ int cal[CAL_V][CAL_H]; char header[HEADER_LEN]; int i, j; int year, month; time_t tt_now; struct tm st_now; tt_now = time(NULL); st_now = *localtime(&tt_now); month = st_now.tm_mon + 1; year = st_now.tm_year + 1900; make_header(month, year, header); printf("%s\n", header); printf("Su Mo Tu We Th Fr Sa\n"); make_cal(month, year, cal); for(i=0;i<CAL_V;i++){ for(j=0;j<CAL_H;j++){ if(cal[i][j] != 0){ printf("%2d ", cal[i][j]); }else{ printf(" "); } } printf("\n"); } }
int be_bc(int todc[2], int fromdc[2]) /* read from stdin and covert into to RPN, send down pipe then read from other pipe and print to user uses fdopen() to convert a file descriptor to a stream */ { char operations[BUFSIZ], message[BUFSIZ]; FILE *fpout, *fpin; int fatal(); /* setup */ close(todc[0]); /* won't read from pipe to dc */ close(fromdc[1]); /* won't write to pipe from dc */ fpout = fdopen(todc[1], "w"); /* convert file dp to streams */ fpin = fdopen(fromdc[0], "r"); if (fpout == NULL || fpin == NULL) { fatal("Error convering pipes to streams"); } while(1) { make_cal(message); printf("\n"); printf("message: %s", message); printf("\n"); if (fprintf(fpout, "%s %c", message, 'p') == EOF) { fatal("Error writing"); } fprintf(fpout, "%s", message); fflush(fpout); if (fgets(message, BUFSIZ, fpin) == NULL) { break; } printf("result: %s", message); } fclose(fpout); fclose(fpin); }