这就是我现在拥有的。
void insert(char Table[][81], char Key[81]){
int index;
index = search(Table, Key);
// This is another function used to find an empty 'slot'
// in the table
if(Table[index] == '\0')
Table[index] = Key;
// <-- This is the line that contains some sort of error.
else
printf("ERROR: Key already in Table\n");
}
它抛出的错误是:
incompatible types when assigning to type 'char[81]' from type 'char *'.
我不知道如何修复或为什么会抛出此错误。如果有人需要我的程序的更多信息来得出结论,请告诉我。
最佳答案
您不能分配数组,但可以使用 strcpy()
或 memcpy()
相反:
if (Table[index][0] == '\0')
memcpy(Table[index], Key, sizeof(Key));
else
printf("ERROR: Key already in Table\n");
关于c - 我无法将 char 字符串分配给 char 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13077207/