[英]Expected Identifier in C Stack using Linkedlist
I am facing several errors when trying to compile my code. 尝试编译我的代码时遇到几个错误。 My code represents a stack using LinkedList and Pointers.
我的代码使用LinkedList和Pointers表示堆栈。 The errors is marked as a comment.
错误标记为注释。 I skipped several methods, because the error occurs in method "Creating new element"
我跳过了几种方法,因为该错误发生在“创建新元素”方法中
This is the error: 这是错误:
In function ‘new_item’:
framework_stack.c:36:9: error: expected identifier or ‘(’ before ‘->’ token
item->info = value;
^
framework_stack.c:37:9: error: expected identifier or ‘(’ before ‘->’ token
item->ptr = NULL;
^
And the code: 和代码:
#include <stdio.h>
#include <stdlib.h>
struct node
{
int info;
struct node *ptr;
}*top,*top1,*temp;
typedef struct node item;
item *top = NULL;
// my methods
void push(item *elem);
void *pop();
void empty();
void create();
int count = 0;
void create()
{
top = NULL;
}
/* Creating new element */
item* new_item(int value)
{
item *temp = malloc(sizeof(item));
item->info = value; // HERE IS THE ERROR
item->ptr = NULL; // HERE IS THE ERROR
}
void push(item *elem)
{
if (top == NULL)
{
top = elem;
}
else
{
top->ptr = elem;
top = elem;
}
count++;
item* head = NULL;
item
is a type, not a variable. item
是类型,而不是变量。
Use 采用
temp->info = value;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.