#include "Hash.h" int MathAscii(char * Mathparnter) { int backnumber = 0; char * move = Mathparnter; if (!Mathparnter) return 0; while (*move != '/0') { backnumber += *move; ++move; } return backnumber; }
#include "Hash.h" int MathAddress(char (*hashname)[CHNUMBER],int *hashrand, Name ** haskeytype) { int i ,j; int MathAddresscount = 0; int pladdress = 0; for (i = 0 ;i <= (*haskeytype)[0].length;++i) { //math the ascii here pladdress = MathAscii(hashname[i]); pladdress %= LENGTH; j = 0; while (!(*haskeytype)[pladdress].flag) { pladdress = (pladdress + hashrand[j]) % LENGTH; ++j; } memcpy((*haskeytype)[pladdress].name,hashname[i],CHNUMBER); (*haskeytype)[pladdress].flag = 1; } return 0; }
#include "Hash.h" int main(int argc , char * argv[]) { char orderecieve; char store[LENGTH][CHNUMBER]; int rdnumber[LENGTH]; Name *hashstore; // clear the array named store memset(store,0,LENGTH*CHNUMBER); printf("Do you really wanna to start the program?/n"); printf("if you really wanna to do that, you should type 'y' or 'Y'/n"); printf("Please input a order to computer./n"); orderecieve = getchar(); fflush(stdin); /* **program init here */ Init(store,rdnumber,&hashstore); while (orderecieve == 'Y' || orderecieve == 'y') { SearchInfo(hashstore,rdnumber); orderecieve = getchar(); fflush(stdin); if (orderecieve != 'Y' || orderecieve != 'y') { printf("Do you really wanna to exit the program./n"); orderecieve = getchar(); } } free(hashstore); return 0; }
#include "Hash.h" int Init(char (*hashname)[CHNUMBER],int *hashrand,Name ** hashkeytype) { *hashkeytype = (Name *)malloc(sizeof(Name) * LENGTH); if (!*hashkeytype) exit(-1); memset(*hashkeytype,0,LENGTH); (*hashkeytype)[0].length = ReadData(hashname); //init the random number RandNumber(hashrand); //math the address where is MathAddress(hashname,hashrand,hashkeytype); return 0; }
#include "Hash.h" int SearchInfo(Name * hashkeytype,int * hashrandom) { int i = 0,j; int sum; char custominput[CHNUMBER]; printf("Please input the student'name you wanna to find./n"); scanf("%s",custominput); sum = MathAscii(custominput); do{ sum %= LENGTH; if (hashkeytype[sum].flag && !strcmp(custominput,hashkeytype[sum].name)) { printf("result: find the student whose/'card is %d",sum); break; } else if (hashkeytype[sum].flag) { j = 0; sum = (sum + hashrandom[j]) % LENGTH; } else { printf("^_^!,no this person."); break; } }while (i < LENGTH); return 0; }
#include "Hash.h" int ReadData(char (*temp)[CHNUMBER]) { int i , j; FILE * pf; pf = fopen("test.txt","r"); if (!pf) exit(-1); for (j = 0; j < LENGTH; ++j) { fscanf(pf,"%s",temp[j]); if (feof(pf)) break; } for (i = 0;i <= j; ++i) { printf("%s/n",temp[i]); } return j; }During programming , I find that these are several programs ,during I’am doing some programming .#include "Hash.h" int RandNumber (int * hashrandnumber) { int * move = hashrandnumber; srand((unsigned)time(NULL)); for (; move <&hashrandnumber[LENGTH]; ++move) { *move = (int)(100.0 * (rand()/(RAND_MAX + 1.0))); } #ifdef _DEBUG move = hashrandnumber; for (; move < &hashrandnumber[LENGTH]; ++move) { printf("%d/n",*move); } #endif // _DEBUG return 0; }
for example , while I make the data struct in the this field,I also realize that I miss the length
Now ,I think I should better find the most meta of the object.
and the program also have some problem like this:
1.the function of functions is not one poupose .for example ,in SearchInfo function,the judging person’s code is in the array or not .I think you could also use function.finally , I last say that using the adding programming thought is a good idea!