/* Program: SPLIT.C Author : Kim Moser Date : 13 April, 1991 System : IBM PC / Borland Turbo C 2.0 Descrip: Given a SORTED text file, splits it into 26 different files, A.OUT, B.OUT, C.OUT, ... , Z.OUT, each containing words which begin with the letter of the filename. Usage : SPLIT #include #include void main(void) { char str[500]; char fname[10] = " .out"; FILE *fout = NULL; while (gets(str) != NULL) { strupr(str); if (str[0] != fname[0]) { fprintf(stderr, "%c", str[0]); if (fout != NULL) { if (fclose(fout)) { fprintf(stderr, "\nfclose() failed for output file.\n"); exit(-1); } } fname[0] = str[0]; if ((fout = fopen(fname, "w")) == NULL) { fprintf(stderr, "\nfopen() failed for '%s'.\n", fname); exit(-1); } } fprintf(fout, "%s\n", str); } fprintf(stderr, "\n"); if (fout != NULL) { if (fclose(fout)) { fprintf(stderr, "fclose() failed for output file.\n"); exit(-1); } } }