gpt4 book ai didi

c - 错误: unknown type name and warning: implicit declaration of function

转载 作者:行者123 更新时间:2023-11-30 21:08:20 25 4
gpt4 key购买 nike

我在使用链表在 C 中实现队列时遇到问题。我已经在 stackoverflow 和其他网站上阅读了很多其他问题,但我仍然不知道如何解决我的代码的这个问题。有人请帮帮我吗?在这里,这是我在 c: 中的代码

#include <stdio.h>
#include <stdlib.h>

struct elem{
int n;
elem *prox;
};

struct fila{
elem *inicio, *fim;
}nop;

void iniciar(fila *d){
d->inicio = (elem*) malloc(sizeof(elem));
d->fim = (elem*) malloc(sizeof(elem));
d->inicio->prox = d->fim;
d->fim->prox = NULL;
}

void inserir(fila *d, int x){
elem *novo = (elem*) malloc(sizeof(elem));
novo->n = x;
novo->fim->prox = NULL;

if(d->inicio->prox == NULL)
d->inicio->prox = novo;
else{
d->fim->prox = novo;
d->fim = novo;
}
}

void deletar(fila *d){
if(d->inicio->prox = NULL)
printf("Lista vazia")
else{
elem *apg;
apg = d->inicio->prox;
d->inicio->prox = apg->prox;
printf("%d", d->n);
free(apg);
}
}

int main(){
int x;

iniciar(&nop);

scanf("%d", &x);

inserir(&nop, x);

deletar(&nop);

return 0;
}

最佳答案

所以,这个问题相当模糊,但是我确实看到了一个问题,那就是你对标签和 typedef 感到困惑。例如:

void inserir(fila *d, int x)

实际上应该定义为

void inserir(struct fila *d, int x)

因为您将 fila 定义为标签。另一种选择是使用 typedef 关键字声明结构 fila(如下所示)

typedef struct elem{
int n;
struct elem *prox;
} element;

typename struct {
element *inicio, *fim;
}fila nop;

关于c - 错误: unknown type name and warning: implicit declaration of function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39399254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com