#include #include #include #define NMAX 20 #define NSTOP 6 #define UNDEF -999 typedef struct { char colstr1[8]; char colstr2[8]; char bsname[NSTOP][12]; } Tableinfo; typedef struct { int number; char company[8]; int hour[NSTOP]; int min[NSTOP]; } Businfo; void printInfo(Businfo b, Tableinfo t) { int j; printf("Number: %d Company: %s\n", b.number, b.company); for (j = 0; j < NSTOP; j++) if (b.hour[j] != UNDEF) printf("%-12s %2d:%02d\n", t.bsname[j], b.hour[j], b.min[j]); putchar('\n'); } int main(int argc, char **argv) { FILE *fp; Tableinfo t; Businfo b[NMAX]; int n = 0, i, j, v, from, to, stop = -1; if (argc != 2) return 1; if (!(fp = fopen(argv[1], "r"))) return 2; fscanf(fp, "%7s%7s", t.colstr1, t.colstr2); for (j = 0; j < NSTOP; j++) fscanf(fp, "%11s", t.bsname[j]); while (n < NMAX && fscanf(fp, "%d%7s", &b[n].number, b[n].company) == 2) { for (j = 0; j < NSTOP; j++) { fscanf(fp, "%d", &v); if (v == UNDEF) b[n].hour[j] = b[n].min[j] = UNDEF; else { b[n].hour[j] = v / 100; b[n].min[j] = v % 100; } } n++; } fclose(fp); char name[20]; printf("Input the name of bus stop.\n"); scanf("%19s", name); for (j = 0; j < NSTOP; j++) if (strcmp(name, t.bsname[j]) == 0) stop = j; printf("Hours from/to?\n"); scanf("%d%d", &from, &to); if (stop >= 0) for (i = 0; i < n; i++) if (b[i].hour[stop] >= from && b[i].hour[stop] <= to) printInfo(b[i], t); return 0; }