本文介绍了我在将字符字符串分配给字符数组时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就是我现在拥有的.
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] == '')
Table[index] = Key;
// <-- This is the line that contains some sort of error.
else
printf("ERROR: Key already in Table
");
}
它抛出的错误是:
从类型 '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.
推荐答案
您不能分配数组,但可以使用 strcpy()
或 memcpy()
代替:
You cannot assign arrays but you can use strcpy()
or memcpy()
instead:
if (Table[index][0] == '')
memcpy(Table[index], Key, sizeof(Key));
else
printf("ERROR: Key already in Table
");
这篇关于我在将字符字符串分配给字符数组时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!