c - 我无法将 char 字符串分配给 char 数组

标签 c arrays char assign

这就是我现在拥有的。

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/

相关文章:

c - 从 opencv 图像打印像素值到屏幕

c - extern 在 main 中调用函数

c - 如果最后一个字符是 ' [space]',程序不会以 EOF 退出并且不会打印

c - 如何在 C 中将 char 数组转换为整数?

c++ - 为什么 C++ 变量是指针时不需要正确定义?

c - 将变量传递给函数时出现问题

c - close() 和 exit() 调用后的 TCP 连接数

javascript - 未捕获的类型错误 : Cannot set property 'innerHTML' of null

php - 如何将数组值添加到 Eloquent ORM::get() 输出

c - 为什么 scanf() 总是什么都不返回?