【发布时间】:2022-01-10 11:29:27
【问题描述】:
出现此警告:
f.c:14:16: warning: incompatible pointer to integer conversion assigning to 'char' from 'char [2]' [-Wint-conversion]
head1 -> data = "K";
^ ~~~
f.c:16:16: warning: incompatible pointer to integer conversion assigning to 'char' from 'char [2]' [-Wint-conversion]
head2 -> data = "a";
^ ~~~
这是代码:
#include <stdio.h>
#include <stdlib.h>
typedef struct _node {
char data;
struct _node *link;
}node;
int main (){
node *head1 = NULL;
node *head2 = NULL;
head1 = (node *)malloc (sizeof (node));
head2 = (node *)malloc (sizeof (node));
head1 -> data = "K";
head1 -> link = head2;
head2 -> data = "a";
printf("%c%c", head1->data, head2->data);
return 0;
}
【问题讨论】:
-
将
head1 -> data = "K";更改为head1 -> data = 'K'; -
@RichardCritten 看起来这是通常的“让我们也标记它 C++ 以获得更多答案”的问题。错误信息中的文件名是
f.c,所以看起来是个C题。 -
您是否通过 C++ 编译器运行您的代码?否则请不要标记 C++ 语言。
标签: c struct linked-list