#include #define DEBUG 0 int main() { FILE *fp; char str[60]; int i,j,k; int tab[256]; int count; int num_coll=0, num_unused=0; scanf("%d",&k); /* opening file for reading */ fp = fopen("input.txt" , "r"); if(fp == NULL) { perror("Error opening file"); return(-1); } //Zero the table for(i=0;i<256;i++) tab[i]=0; //read every line till the end of file while( fgets (str, 60, fp)!=NULL ) { /* replace '\n' by '\0'; removing new line charcater */ i=0; for(i=0; str[i] != '\0';i++) if(str[i] == '\n') str[i]='\0'; /* adding all characters in the satring mod k */ count=0; for(i=0; str[i] != '\0'; i++) count = (count + (int) str[i])%k; // this line mapped to count, increase tab[count] by one tab[count]++; } fclose(fp); //for debugging purpose, if you want it to print the table, make DEBUG //at the beginning of the code 1 (in #define DEBUG) if(DEBUG) { for(i=0; i1? num_coll++:num_coll; tab[i]==0? num_unused++:num_unused;} printf("The number of entries with collision is %-5d\n", num_coll); printf("The number of unused entries is %-5d\n", num_unused); return(0); }