/**************************************************************************/ /* CSE2304 Prac3B Sample Source Code */ /**************************************************************************/ #include #include #include "routines.h" int process(int input) { if(((input>='A')&&(input<='Z'))||((input>='a')&&(input<='z'))) return 1; else return 0; } int main(int argc, char *argv[]) { int input; FILE *fp1, *fp2; struct Element *record; int size_array; int i,index,rank000; char buffer[LIMIT]; int count000=0; int count1,count2; if(argc<3) { printf("The Usage of the program is:\n"); printf("prac3b [text file to be parsed] [dictionary of words]\n"); exit(0); } if((fp2=fopen(argv[1],"r"))==NULL) { printf(" The program can't open the text file, please check the directory and the file name\n"); exit(0); } if((fp1=fopen(argv[2],"r"))==NULL) { printf(" The program can't open the dictionary file, please check the directory and the file name (normally it is /usr/share/dict/words)\n "); exit(0); } size_array=size(fp1); fclose(fp1); fp1=fopen(argv[2],"r"); record=(struct Element *)malloc(sizeof(struct Element)*size_array); for(i=0;i='A')&&(buffer[index]<='Z')) buffer[index]+=32; /* if uppercase convert to lower case */ } if((index=check(buffer,record,size_array-1))>=0) { count(record,index); for(index=0;index=0) count(record,index); else count000++; for(index=0;indexcount1) sort_length(record,count1,count2); count1=count2+1;count2=count1; } /* end of the length sorting */ /* begin to sort the elements with the same length by alphabetical sequence*/ count1=0;count2=count1; while(count1<(size_array-1)) { while(record[count2+1].length==record[count1].length) { count2++; if(count2==(size_array-1)) break; } if(count2>count1) sort_alpha(record,count1,count2); count1=count2+1;count2=count1; } /* end of the alhabetical sorting */ printf(" The source file is successfully parsed!\n"); printresult(record,size_array,count000); free(record); /* free the memory allocated to the records */ printf(" Game Over! Thanks for your Using!\n"); fclose(fp1); fclose(fp2); exit(0); }