簡體   English   中英

我無法將char字符串分配給char數組

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

這就是我現在擁有的。

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

它拋出的錯誤是:

從類型'char *'分配類型'char [81]'時不兼容的類型。

我不知道如何修復或為什么拋出這個錯誤。 如果有人需要我的程序中的更多信息來得出結論,請告訴我。

您不能分配數組,但可以使用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