This code we can use to create some bucket based on file disk. In case you dont have to much memory ram to take care Hashtable. (-:
int writeFileBucket(unsigned int hash, char *keyword)
{
FILE *bucketWrite = NULL;
char temp[30] = "";
char *file;
file = malloc(100);
strcpy(file,"bucket");
sprintf(temp,"%d",hash);
strcat(file,temp);
char buffer[500];
strcpy(buffer,keyword);
size_t len = 0;
//try to open file to append
bucketWrite = fopen(file,"a");
if (bucketWrite==NULL) // some problem to create file on disk system
{
printf("\n Proble to create bucketFile: %s",file);
return -1;
}
else {
strcat(buffer," ");
len = strlen(buffer);
fwrite(buffer, len, 1, bucketWrite);
fclose(bucketWrite);
return 0;
}
free(file);
}
Nenhum comentário:
Postar um comentário