I'm trying to implement a linked list in C, and i'm having a hard time figuring out why I'm getting the following error when compiling:
entryList.c:7:11: error: 'tmp' undeclared (first use in this function)
entry * tmp = NULL;
entryList.c:7:11: note: each undeclared identifier is reported only once for
each function it appears in
^
I already wrote a few linked lists for this program, they all use a similar syntax, but the compiler only complains about this one.
I have my struct definition in header.h:
/*definition of entry type*/
typedef struct entry
{
char * label;
short int address;
struct entry * next;
} entry;
and in entryList.c, I'm writing a function to add a node to the linked list.
#include "header.h"
static entry * head = NULL;
void addEntry(char * entry, int line)
{
entry * tmp = NULL;
char * label = NULL;
tmp = malloc(sizeof(entry));
label = malloc(sizeof(char)*MAX_LINE);
strcpy(tmp->label, entry);
tmp->address = 0;
tmp->next = NULL;
if (!head)
{
head = tmp;
}
else
{
entry * p = head;
while (p->next)
p = p->next;
p->next = tmp;
}
}
void addEntry(char * entry, int line)
{
entry * tmp = NULL;
You have both a parameter and a type named entry
. Change one of them to something else.