johne@athena.TEK.COM (John F. Ewing Jr.) (03/18/87)
I wrote a little C program that formats the coin-price-list data and prints it out in a report. Its nothing to brag about (I do not apologize about the coding style), but it may save you some time if you want to do this too. The report fits inside 132 columns and is 53 pages long. To run it, redirect standard output from the file containing the coin- price-list data and the report is printed out on standard output. Enjoy . . . johne@athena@tektronix - - - - C U T H E R E - - - - - - - - - - - - - - - - C U T H E R E - - - - /* * Name: coin.c * * Description: Read a file of formatted "Coin Price List" data and print * a report. The file has 15 fields, each field separated by semi- * colins. The fields are: * * value, type, date, design, comments, mintage, value(9) * * There are values for 9 possible conditions: * * almost good, good, very good, fine, very fine, extra fine, * almost uncirculated, uncirculated, and proof. * * See the README file --> part of the original "Coin Price List" posting. */ #include <stdio.h> main () { int c, x, line=99, page=1; char *type[17], *old_type[17], *design[22], *old_design[22], *date[6], *comment[18], *mintage[13], *cond_ag[7], *cond_gd[7], *cond_vg[8], *cond_fn[8], *cond_vf[8], *cond_ef[8], *cond_au[8], *cond_un[9], *cond_pr[9]; while ((c = getchar ()) != '\n') ; while ((c = getchar ()) != EOF) { while ((c = getchar ()) != ';') ; get_field (&c, 17, type); get_field (&c, 6, date); get_field (&c, 22, design); get_field (&c, 18, comment); get_field (&c, 13, mintage); get_field (&c, 7, cond_ag); get_field (&c, 7, cond_gd); get_field (&c, 8, cond_vg); get_field (&c, 8, cond_fn); get_field (&c, 8, cond_vf); get_field (&c, 8, cond_ef); get_field (&c, 8, cond_au); get_field (&c, 9, cond_un); get_field (&c, 9, cond_pr); lower_to_upper (type); if (strcmp (type, old_type)) if (line > 45) heading (&line, page++, type, design); else { printf ("\n%-s\nDesign: %-s\n\n", type, design); line += 4; } else if (strcmp (design, old_design)) if (line > 45) heading (&line, page++, type, design); else { printf ("\nDesign: %-s\n\n", design); line += 3; } for (x=0; x<17; x++) old_type[x] = type[x]; for (x=0; x<22; x++) old_design[x] = design[x]; if (line > 50) heading (&line, page++, type, design); printf ("%-6s %-18s %13s %7s %7s %8s %8s %8s %8s %8s %9s %9s \n", date, comment, mintage, cond_ag, cond_gd, cond_vg, cond_fn, cond_vf, cond_ef, cond_au, cond_un, cond_pr); line++; } } heading (line, page, type, design) int *line, page; char *type, *design; { *line = 0; if (page > 1) printf ("\f"); printf ("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tPage: %-d\n\n", page); printf (" Almost "); printf ("Very Very Extra Almost Uncir-\n"); printf ("Date Comments Mintage Good Good "); printf ("Good Fine Fine Fine Uncircul culated Proof\n"); printf ("---- -------- ------- ------ ---- "); printf ("---- ---- ---- ----- -------- ------- -----\n\n"); printf ("\n%-s\nDesign: %-s\n\n", type, design); } strcmp (s1, s2) /* return "1" if they are different */ char *s1, *s2; { int x; for (x=0; (s1[x]==s2[x] && s1[x]!='\0' && s2[x]!='\0'); x++) ; return (!(s1[x] == '\0' && s2[x] == '\0')); } get_field (c, k, field) int *c, k; char *field; { int x = 0; *c = getchar (); while (k-- > 0 && *c != ';' && *c != '\n') { field[x++] = *c; *c = getchar (); } field[x] = '\0'; while (*c != ';' && *c != '\n') *c = getchar (); } lower_to_upper (t) char *t; { int x; for (x = 0; t[x] != '\0'; x++) if (t[x] > ('a'-1) && t[x] < ('z'+1)) t[x] -= 'a' - 'A'; }