【发布时间】:2018-12-27 01:48:13
【问题描述】:
我想知道带 10 个名字的文本文件并阅读它。 10个名字按降序排序,用除法形成哈希表。我需要构建它们的链表。哈希表的索引为 7。
我已经尝试过匹配指针变量并制作了一个哈希表,但我做不到。我在制作哈希表、插入数据、打印哈希表和搜索数据时遇到了麻烦(当我键入名称时要查找的函数。)。我需要添加更多功能..我是怎么做到的?
#define SIZE 7
struct node {
char data[100][20];
struct node* next;
};
struct index {
struct node* head;
int count;
};
struct sum (data){
struct node* ptr;
int sum,i;
for (i=0; i<20; i++) {
ptr -> data[i] = ptr;
strcpy(sum,ptr);
}
return sum;
};
int hashFunction (int sum) {
return sum%SIZE;
}
void descend (data) {
int temp;
for(i=0;i<100;i++) {
for(j=0;j=20;j++) {
if (data[i][j+1]>data[i][j])
temp=data[i][j];
data[i][j]=data[i][j+1];
data[i][j+1]=temp;
}
}
}
int main (void) {
char data[100][20];
FILE *fp;
fp = fopen("data.txt","r");
for (int i=0; i<20; i++)
fscanf (fp,"%s",&data);
printf("%s\n",data);
}
fclose(fp);
hashTable = (struct index*)malloc(SIZE*sizeof(struct index));
descend(data);
return 0;
}
【问题讨论】:
-
这
fscanf (fp,"%s",&data)不应该是fscanf (fp,"%s",&data[i]),因为data是二维数组。 -
该代码中有很多错误,请编译并询问所有警告并查看编译器产生的错误和警告以修复它们
标签: c