指向struct"未声明(在此函数中首次使用)"的指针

fis*_*mit 0 c linked-list undeclared-identifier

我正在尝试在C中实现一个链表,我很难搞清楚为什么我在编译时遇到以下错误:

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
       ^
Run Code Online (Sandbox Code Playgroud)

我已经为这个程序写了一些链表,它们都使用了类似的语法,但编译器只抱怨这个.

我在header.h中有我的结构定义:

/*definition of entry type*/
typedef struct entry
{
  char * label;
  short int address;
  struct entry * next;
} entry;
Run Code Online (Sandbox Code Playgroud)

在entryList.c中,我正在编写一个函数来将一个节点添加到链表中.

#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;
  }
}
Run Code Online (Sandbox Code Playgroud)

Cro*_*man 6

void addEntry(char * entry, int line)
{
    entry * tmp = NULL;
Run Code Online (Sandbox Code Playgroud)

您有一个参数和一个名为的类型entry.将其中一个更改为其他内容.