2012-10-25 60 views
1

這是我現在有。我無法分配中一個字符串的字符數組

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 [81]' 時。

我不知道如何解決或爲什麼會拋出此錯誤。如果有人需要從我的程序得到更多信息來得出結論,請告訴我。

回答

4

您不能分配數組,但你可以使用strcpy()memcpy()代替:

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