我收到一条错误消息,提示“参数类型” const char *
“与“”不兼容char *
。此代码由我的教授提供,我不确定问题出在哪里。
我正在编写 C,但我使用的是 C++ 编译器,因为如果这很重要,它更容易调试。
int main() {
int i;
Dictionary A;
char* str;
char* v;
char* k = (char*)calloc(100, sizeof(char));
// create a Dictionary and some pairs into it
A = newDictionary();
insert(A, "1", "a"); // it doesn't like "1" or "a"
// here is the function:
// insert()
// inserts new (key,value) pair into the end (rightmost part of) D
// pre: lookup(D, k)==NULL
void insert(Dictionary D, char* k, char* v) {
Node N, A, B;
if (D == NULL) {
fprintf(stderr,
"Dictionary Error: calling insert() on NULL Dictionary reference\n");
exit(EXIT_FAILURE);
}
if (findKey(D->root, k) != NULL) {
fprintf(stderr,
"Dictionary Error: cannot insert() duplicate key: \"%s\"\n", k);
exit(EXIT_FAILURE);
}
N = newNode(k, v);
B = NULL;
A = D->root;
while (A != NULL) {
B = A;
if (strcmp(k, A->key) != 0) {
A = A->right;
}
}
if (B == NULL) {
D->root = N;
}
else {B->right = N;}
D->numPairs++;
}