#include #include char codes[500][4]; void main(void) { FILE *codf, *script, *flights; char line[100]; int i,n=0; int src, dst, dhr, dmn, dur, ahr, amn, cap, meal; srand(time(NULL)); codf=fopen("airportcodes.txt","r"); if (codf==NULL) exit(1); script=fopen("makeflights","w"); if (script==NULL) exit(1); flights=fopen("flights","w"); if (flights==NULL) exit(1); fprintf(script,"create table flights\n"); fprintf(script,"( num int,\n"); fprintf(script," src char(3),\n"); fprintf(script," deptime int,\n"); fprintf(script," dest char(3),\n"); fprintf(script," arrtime int,\n"); fprintf(script," capacity int,\n"); fprintf(script," meal char(1));\n"); fprintf(flights,"FLT DEP H_ M_ ARR H_ M_ CAP M\n"); while (1) { char *s; s=fgets(line,99,codf); if (s==NULL) break; strncpy(codes[n],line,3); n+=1; } fclose(codf); for (i=100; i<200; i+=1) { src=rand()%n; dst=src; while (dst==src) dst=rand()%n; dhr=rand()%24; dmn=rand()%60; dur=60+rand()%300; amn=dmn+dur; ahr=dhr+(amn/60); amn=amn%60; ahr=ahr%24; cap=70+rand()%300; meal='N'; if ((dur>200) && (rand()%2)) meal='Y'; fprintf(flights,"%03d %3s %02d %02d %3s %02d %02d %03d %c\n", i,codes[src],dhr,dmn,codes[dst],ahr,amn,cap,meal); fprintf(script,"insert into flights values (%03d,\'%3s\',%02d%02d,\'%3s\',%02d%02d,%3d,\'%c\');\n", i,codes[src],dhr,dmn,codes[dst],ahr,amn,cap,meal); } fclose(flights); fclose(script); }