/* Driver program to test above function */ int main(void) { convert_to_words("9923"); convert_to_words("523"); convert_to_words("89"); convert_to_words("8989"); return 0; }
int main() { FILE *fp, *fpd, *fpo; char c; char buffer[MAXS]; char outbuffer[MAXS2] = ""; char dictionary[DICS]; char* token; double flag; int isreplaced=0; int numcount=1; /* Open file for both reading and writing */ fprintf(stderr, "Opening files ...\n"); fp = fopen("input.txt", "r+"); fpd = fopen("dictionary.txt", "r+"); fpo = fopen("output.txt", "w+"); /* Write data to the file */ //fwrite(c, strlen(c) + 1, 1, fp); /* Seek to the beginning of the file */ //fseek(fp, SEEK_SET, 0); /* Read and display data */ //fread(buffer, sizeof(buffer)+1, 1, fp); fgets(buffer, sizeof(buffer), fp); remove_newline_ch(buffer); printf("Input paragraph;\n%s\n", buffer); /* while(!feof(fpd)) { fgets(dictionary, sizeof(dictionary), fpd); printf("%s\n", dictionary); }*/ token = strtok(buffer, " "); while (token) { remove_punct_and_make_lower_case(token); // printf("\n\ntoken: %s, lenght: %d\n\n\n", token, strlen(token)); // checking for numbers if(is_valid_int(token)){ printf("\nNumber %d: %s",numcount, token); numcount++; convert_to_words(token); strcat(outbuffer, token); strcat(outbuffer, " "); } else { if(strlen(token) >= 4){ // checking for spelling fseek(fpd, SEEK_SET, 0); isreplaced = 0; while(!feof(fpd)) { flag = 0.0; fgets(dictionary, sizeof(dictionary), fpd); remove_punct_and_make_lower_case(dictionary); remove_newline_ch(dictionary); // printf("%s\n", dictionary); if(strlen(token) >= 4){ flag = is_similar(token, dictionary); /*{ strcat(outbuffer, token); strcat(outbuffer, " "); }if(flag == 0.0){ strcat(outbuffer, token); strcat(outbuffer, " "); } else */ if(isreplaced != 1){ if(flag > 0.6){ strcat(outbuffer, dictionary); strcat(outbuffer, " "); isreplaced = 1; } else if(flag == 1.0){ strcat(outbuffer, token); strcat(outbuffer, " "); isreplaced = 1; } } } } if(isreplaced == 0){ strcat(outbuffer, token); strcat(outbuffer, " "); } } else { strcat(outbuffer, token); strcat(outbuffer, " "); } } token = strtok(NULL, " "); } fwrite(outbuffer, strlen(outbuffer) + 1, 1, fpo); fclose(fp); fclose(fpd); fclose(fpo); return(0); }