簡體   English   中英

指向結構的指針“未聲明(此函數中的第一次使用)”

[英]Pointer to struct “undeclared (first use in this function)”

我正在嘗試在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
       ^

我已經為該程序編寫了一些鏈接列表,它們都使用類似的語法,但是編譯器僅對此抱怨。

我在header.h中有我的結構定義:

/*definition of entry type*/
typedef struct entry
{
  char * label;
  short int address;
  struct entry * next;
} entry;

在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;
  }
}
void addEntry(char * entry, int line)
{
    entry * tmp = NULL;

您同時具有一個參數和一個名為entry的類型。 將其中之一更改為其他內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM