我为双链接列表创建了一个结构和功能。对于整数来说,它工作得非常完美,但是现在我必须将它转换为使用字符。当涉及到字符时,我总是遇到一个问题,当我输入一个字符时,我会得到一个固定的循环。
到目前为止,我已经:
struct node
{
struct node *previous;
char data;
struct node *next;
}*head, *last;
void begin(char value)
{
struct node *temp;
char *var=(char *)malloc(sizeof(char)*100);
var->data=value;
if(head==NULL)
{
head=var;
head->previous=NULL;
head->next=NULL;
last=head;
}
else
{
temp=var;
temp->previous=NULL;
temp->next=head;
head->previous=temp;
head=temp;
}
} 我使用了以前使用字符的push/pop函数中的一些例子,但我不知道自己做错了什么。
编辑:忘记将errors> null.c:14: error:对成员“数据”的请求放在非结构或联合null.c:17中:警告:来自不兼容指针类型的赋值
发布于 2013-05-09 19:27:50
char *var=(char *)malloc(sizeof(char)*100);这应该是,
struct node *var= malloc( sizeof( struct node ) );发布于 2013-05-09 19:28:51
这是correct...the类型的var不是'struct节点‘,所以您不能执行var->数据。
https://stackoverflow.com/questions/16469518
复制相似问题