【问题标题】:When i try to compile i got expected * but argument is type **, and warnings passing argument incompatible pointer type [closed]当我尝试编译时,我得到了预期的 * 但参数是 ** 类型,并且警告传递参数不兼容的指针类型 [关闭]
【发布时间】:2017-06-06 01:42:57
【问题描述】:
listT *Stos;
void DFS(int wierz) {
  int v;
  nodeT *p;
  addfront(&Stos, wierz);
  tabzaznaczen[wierz] = 1;
  while (Stos) {
    removefront(&Stos, &v);
    printf("%d\n", v);
    for (p = tabwierz[v].front; p; p = p->next) {
      if (tabzaznaczen[p->data] == 0) {
        addfront(&Stos, p->data);
        tabzaznaczen[p->data] = 1;
      }
    }
  }

当我将声明更改为listT Stos; 时,它显示的错误是:在需要标量时使用了 struct tpye 值。然后当我更改为while(&Stos) 时,我\while 去无穷大。

typedef struct nodeTAG{
int data;
struct nodeTAG *next;
}nodeT;

typedef struct listTAG{
nodeT *front;
nodeT *end;
}listT;


void listinit (listT *plist)
{
plist -> front = NULL;
plist -> end = NULL;
}

int isempty (listT *plist)
{
if (plist -> front == NULL)
return 1;
else   return 0;
}

void addfront (listT *plist, int x)
{
nodeT *temp;
temp = (nodeT*)malloc(sizeof(nodeT));
temp -> data =x;

if (plist -> front == NULL)
{
temp -> next = NULL;
plist -> front = temp;
plist -> end = temp;
}
else
{
temp -> next = plist -> front;
plist -> front = temp;
}
}

void addend (listT *plist, int x)
{
nodeT *temp;
temp = (nodeT*)malloc(sizeof(nodeT));
temp -> data = x;

if (plist -> front == NULL)
{
temp -> next = NULL;
plist -> front = temp;
plist -> end =temp;
}
else
{
temp -> next = NULL;
plist -> end -> next = temp;
plist -> end = temp;
}
}

void removefront (listT *plist, int *x)
{
if (isempty(plist) == 0)
{
nodeT *temp;
*x=plist->front->data;
temp = plist -> front;
plist -> front = temp -> next;
free(temp);

}
}

这是列表。顺便说一句,程序正在正常工作,只是那些警告正在困扰我向我的老师展示。如果你能告诉我如何解决这些问题,我会很高兴。

【问题讨论】:

  • 确切错误信息是什么?
  • 该函数需要一个指针listT*,但被传递一个指针指针listT**,然后无限循环是这里的主要线索。 &Stos 是一个指针指针。
  • 问题被搁置,我无法发布答案,所以我会在评论中回答。将 listT *Stos; 更改为 listT Stos; 否则,您会将未初始化指针的地址传递给期望指向 listT 的指针的函数。
  • 或者,listT* Stos = malloc(sizeof(listT)); 和 addfront(Stos, 1);

标签: c pointers graph microsoft-distributed-file-system


【解决方案1】:

很高兴看到所用函数的函数原型,但看起来你需要一个指向列表指针的指针,这样当 removefront 删除第一个节点并将指针重新分配给新的头时,它不会丢失回来了。

这里有一个很棒的链表教程:http://www.learn-c.org/en/Linked_lists

【讨论】:

  • 我已经添加了功能。
猜你喜欢
  • 2011-01-10
  • 2020-07-29
  • 2014-12-03
  • 2021-06-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多