我无法将 char 字符串分配给 char 数组 [英] I am having trouble assigning a char string to a char array
本文介绍了我无法将 char 字符串分配给 char 数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就是我现在所拥有的.
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] == ' ')
Table[index] = Key;
// <-- This is the line that contains some sort of error.
else
printf("ERROR: Key already in Table
");
}
它抛出的错误是:
从类型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] == ' ')
memcpy(Table[index], Key, sizeof(Key));
else
printf("ERROR: Key already in Table
");
这篇关于我无法将 char 字符串分配给 char 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文