This program reads words from a dictionary text file and writes all of the words that end in 'man' to another file. I know this is probably a very strange way to do this but it's what I have after trying it a few ways.
It works, and writes all the words to the file, but it crashes after reading through all of the words in the dictionary file. I don't know why (ms vc++ 6.0).
Code:if ((dictfile = fopen("/aacraig/dict.txt", "r"))==NULL) { printf("Cannot open this file\n"); exit(1); } while(!feof(dictfile)) { next_char = 0; count=0; for (i=0; next_char!=10; i++) { /* read one line in */ fscanf(dictfile, "%c", &next_char); array[i] = next_char; count++; } //printf("count is %d\n", count); wordfile = fopen("/aacraig/wordfile.txt", "a"); if ((array[count - 2] == 'n') && (array[count - 3] == 'a') && (array[count - 4] == 'm')) for(i=0; i<count; i++) fprintf(wordfile, "%c", array[i]); printf("\n"); fclose(wordfile); } fclose(dictfile);



LinkBack URL
About LinkBacks



