我不能找到此语法错误,其读取:预期标识符或“(”前“字符”语法错误
/home/ubuntu/workspace/stack.c:6:12: error: expected identifier or ‘(’ before ‘char’
char stack(char cmd[40])
^
的^符号在堆(炭第二个C下是,我看我找不到答案,其中大部分都是简单的东西;在主函数结尾处,但是我看不出有什么问题,任何人都有一个想法?
stack.c
#ifndef stack
#define stack
#include <stdio.h>
#include "stack.h"
char stack(char cmd[40])
{
stacks newstack()
{
stacks s;
s -> head = NULL;
return s;
}
void deletestack(stacks s)
{
node temp;
while(s -> head)
{
temp = s -> head;
s -> head = s -> head -> next;
free(temp);
}
free(s);
}
int isEmpty(stacks s)
{
if(s -> head == NULL)
return 1;
else
return 0;
}
void push(stacks s, element e)
{
node n = (node)malloc(sizeof(node_type));
n -> e = e;
n -> next = s -> head;
s -> head = n;
}
element peek(stacks s)
{
return s -> head -> e;
}
void display(stacks s)
{
while(s -> head)
{
printf("%d\n", s -> head -> e);
}
}
element pop(stacks s)
{
printf("%d\n", s -> head -> e);
temp = s -> head;
s -> head = s -> head -> next;
free(temp);
}
}
#endif
stack.h
#ifndef ____Linked_List_H____
#define ____Linked_List_H____
#include "stdheader.h"
//Structures
//element is content of a node.
typedef int element;
//node is 1 link in a linked list.
struct _node{
element e;
struct _node* next;
};
typedef struct _node node_type;
typedef struct _node* node;
//linked list is a series of links tracked by the head or start of the list. struct _linked_list{
node head;
};
typedef struct _linked_list stacks_type;
typedef struct _linked_list* stacks;
stacks newstack();
void deletestack(stacks);
int isEmpty(stacks);
element pop(stacks);
void push(stacks, element);
element peek(stacks);
void display(stacks);
#endif
看起来好像你从'stack.h'中缺少一个分号。你可以发布该代码吗?此外,您正试图在函数内部定义函数,这在C中是不允许的。 – templatetypedef
您错过了头文件中的某些内容。 – Holsety
以双下划线开头的标识符被保留用于实现。不要在用户代码中使用它们!并且不要'输入'指针!这混淆了语义,并且是对代码中的逻辑错误的邀请。 – Olaf