// syntax : labnik !.num !.lab out #include #include #include #define boolean int #define false 0 #define true 1 void panic (void); main (int argc, char* argv[]) { FILE *labfile, *datafile, *outfile; char* string = (char*) malloc (513 * sizeof (char)) ; char* dirname = (char*) malloc (513 * sizeof (char)) ; char* outname = (char*) malloc (513 * sizeof (char)) ; char* command = (char*) malloc (513 * sizeof (char)) ; boolean clustered[10000] = {false}; // does thepoint belong to a cluster int number; // number of cluster int counter; // number of points in cluster int lnum; // line number read form .lab file int nread; // lines read from datafile if ( ! (datafile = fopen (argv[1], "r"))) { printf (" No input file \n") ; exit (0); } if ( ! (labfile = fopen (argv[2], "r"))) { printf (" No input file \n"); exit (0); } number = 1; while ( fscanf ( labfile, "%i", &counter ) ) { if (counter < 0) break; sprintf ( outname, "%s.%i", argv[3], number++); //outfile outfile = fopen (outname, "w"); nread = 0; while ( counter-- ) { fscanf ( labfile, "%d", &lnum); clustered [++lnum] = true; ; while ( ++nread <= lnum ) fgets (string, 512, datafile); if (--nread > lnum) panic (); fputs (string, outfile); } fclose (outfile); sprintf (command, "count %s %s.c", outname, outname); system (command); freopen ( argv[1], "r", datafile); } // reading the __ cluster sprintf ( outname, "%s._", argv[3] ); // __ cluster name outfile = fopen (outname, "w"); for (counter = 1; fgets (string, 512, datafile); counter++) if (! clustered [counter] ) fputs (string, outfile); fclose ( outfile ); sprintf (command, "count %s %s.c", outname, outname); system (command); // sprintf (dirname , "t%i", number); // sprintf (command , "mkdir %s", dirname); // system (command); // sprintf (command, "mv *.c %s", dirname); // system (command); fclose (datafile); fclose (labfile); } void panic (void ) { printf (" panic !!! \n" ) ; exit (1) ; }