c - 帮助处理 C 中的指针、文件和函数

标签 c

编译时抛出 3 个错误,我使用的是 Dev-C++。

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

struct agenda{
    char nombre [50];
    char telefono[25];
    char email[50];
    }
    struct nodo{
        struct agenda dato;
        struct nodo *proximo;    
        } 

    struct nodo *nuevonodo
           int colavacia(struct nodo *)
    struct nodo *creacola (struct nodo *, struct agenda);

    void mostrar (struct nodo *);

    void main()
    {
        struct nodo *pri=NULL, *ult=NULL;
        struct agenda x;

        printf ("ingrese nombre: ");
        gets(x.nombre);
        while (strcmpi(x.nombre, "fin"))

    {
        printf ("ingrese telefono: ");
        gets (x.telefono);
        printf ("ingrese mail: ");
        gets(x.mail);
        ult=creacola(ult,x);
        if (pri==NULL) pri=ult; //si es la 1 pasada pongo en pri el valor del primer nodo
        printf ("ingrese nombre: ");
        gets(x.nombre);
    }
    if (colavacia(pri)==1)
    {
    printf ("No se ingresaron registros");getch();
    }
    else mostrar(pri);

    }
    struct nodo *nuevonodo()
    {
        struct nodo *p;
        p=(struct nodo *)malloc(sizeof(struc nodo));
        if(p==NULL)
        {
            printf ("memoria ram llena");
            getch();
            exit(0);
        }
        return p;
    }

    struct nodo *creacola(struct nodo *ult, struct agenda x)
    {
        struct nodo *p;
        p=nuevonodo();
        (*P).dato=x;
        (*p).proximo=NULL;
        if(ult!=NULL) (*ult).proximo=p; //si hay nodo anterior en prox pongo la direccion del nodo actual
        return p;
    }

    int colavacia(struct nodo *pri)
    {
        if(pri==NULL) return 1;
        else
        return 0;
    }

    void mostrar (struct nodo *pri)
    {
        struct nodo *aux;

    while(pri!=NULL)
    {
        printf("Nombre: %s - telefono: %s - Mail: %s \n", 
        pri->dato.nombre,pri->dato.telefono,pri->dato.mail);
        aux=pri;
        pri=(*pri).proximo;
        free(aux);
    }
    getch();
}

最佳答案

您必须以分号结束 struct 定义:

struct agenda{
    char nombre [50];
    char telefono[25];
    char email[50];
}; // <- HERE

对于变量和函数声明类似:

struct nodo *nuevonodo;
int colavacia(struct nodo *);

main 的返回值类型为int

关于c - 帮助处理 C 中的指针、文件和函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5587527/

相关文章:

c - C 预处理器警告/错误消息中的字符串插值

c - MikroC、dsPIC UART 接收中断问题

两个字符指针的比较

c - 高分辨率的 C 语言精确计时

c++ - 使用 loadappinit_dlls 注册表项将 dll Hook 到正在运行的进程中

c - 我想消除我在程序中绘制的表格的重复外观。有没有办法可以将其放入单独的函数中?

python - 如何生成数字范围的所有组合

c - C中不同文件的 union 变量

objective-c - Objective C 语法错误

c - 在 C 标准库中转发声明实体?