简体   繁体   English

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

[英]I am having trouble assigning a char string to a char array

This is what I have now. 这就是我现在拥有的。

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");
}

The error it is throwing is: 它抛出的错误是:

incompatible types when assigning to type 'char[81]' from type 'char *'. 从类型'char *'分配类型'char [81]'时不兼容的类型。

I am at a loss as to how to fix or why this error is being thrown. 我不知道如何修复或为什么抛出这个错误。 If anyone needs more info from my program to draw a conclusion please let me know. 如果有人需要我的程序中的更多信息来得出结论,请告诉我。

You cannot assign arrays but you can use strcpy() or memcpy() instead: 您不能分配数组,但可以使用strcpy()memcpy()代替:

if (Table[index][0] == '\0')
    memcpy(Table[index], Key, sizeof(Key));
else
    printf("ERROR: Key already in Table\n");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM