我有麻烦指定一个字符字符串到字符数组 [英] 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");
}
这是引发错误是:
The error it is throwing is:
不兼容的类型分配给从类型类型的char *''的char [81]时。
incompatible types when assigning to type 'char[81]' from type 'char *'.
我在一个不知如何解决,或者为什么被抛出此错误。如果有人需要从我的程序的详细信息,以得出一个结论,请让我知道。
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] == '\0')
memcpy(Table[index], Key, sizeof(Key));
else
printf("ERROR: Key already in Table\n");
这篇关于我有麻烦指定一个字符字符串到字符数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文