int main(void) { FILE *fp, *fp2; /*File pointers*/ triplet_t triplet_to_search; /*For search*/ Row mpn_table[TABLE_SIZE]; /*Table array*/ int actual_size; /*Actual size or number of row in table*/ /*Open table.txt if file couldn't open prints the screen warning message*/ fp=fopen("table.txt", "r"); if(fp==NULL) printf("table.txt couldn't open"); /*Open converted.bin if file couldn't open prints the screen warning message*/ fp2=fopen("converted.bin", "wb"); if(fp==NULL) printf("converted.bin couldn't open"); /*Reads informations from text file and writes them to binary file*/ Into_Binary(fp,fp2); fclose(fp); fclose(fp2); /*Open converted.bin if file couldn't open prints the screen warning message*/ fp2=fopen("converted.bin", "rb"); if(fp==NULL) printf("converted.bin couldn't open"); /*Reads informations from binary file and records in table array returns number of row*/ actual_size=Load_Mpn_table(fp2, mpn_table, 10); /*Takes from the user a combination-of-positives triplet*/ printf("\nEnter combination-of-positives triplet:"); scanf("%d%d%d", &triplet_to_search.one, &triplet_to_search.two, &triplet_to_search.three); /*Search for it in the table*/ search(mpn_table, actual_size, triplet_to_search); fclose(fp2); return 0; }
int main() { Row_t table[10]; /*Table for coping information which is in the text file*/ Row_t show; /*Used for show full information of searched values */ triplet_t searchval;/*Search value */ int size; /*size */ FILE *text_inp, /*Text File File pointer's*/ *binary_out; /*Binary File File pointer's*/ /*Opening files*/ text_inp = fopen(TEXT_FILE,"r"); binary_out = fopen(BINARY_FILE,"wb"); /*Transforming to binary file*/ while(!feof(text_inp)) Into_Binary(text_inp,binary_out); fclose(text_inp); fclose(binary_out); /*Opening binary file read mode*/ binary_out = fopen(BINARY_FILE,"rb"); /*Get search triplet*/ printf("Enter combination of positives triplet by white spaces>>> \n"); scanf("%d%d%d",&searchval.s1,&searchval.s2,&searchval.s3); /*Used when debugging*/ #if defined (DEBUG) Row_t as; while(!feof(binary_out)) { fread(&as,sizeof(as),1,binary_out); printf("%d %d %d %d %d %d \n" ,as.triple.s1,as.triple.s2,as.triple.s3 ,as.index,as.lower,as.upper); } #endif /*Main process*/ while(!feof(binary_out)) { /*Get table And process with the information*/ size = Load_Mpn_table(binary_out,table,10); show = search(table,size,searchval); /*if index member different from zero that means there is match because*/ /*changed initial value */ if(show.index != 0) { /*Showing founded values*/ printf("There is a match found: \n"); printf("MPN=%d; 95%% of samples contain between %d and %d bacteria/ml." ,show.index,show.lower,show.upper); return 0; } } printf("There is no match found with this values >>> %d %d %d.",searchval.s1 ,searchval.s2 ,searchval.s3); return 0; }