помогите с указателями, файлами и функциями в c - PullRequest
1 голос
/ 08 апреля 2011

выдает мне 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();
}

Ответы [ 2 ]

3 голосов
/ 08 апреля 2011
5587527.c:2:19: fatal error: conio.h: No such file or directory

Я прокомментировал оскорбление #include и попробовал еще раз

5587527.c:11:5: error: two or more data types in declaration specifiers
5587527.c:16:5: error: two or more data types in declaration specifiers
5587527.c:17:12: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
cc1: warnings being treated as errors
5587527.c:22:10: error: function declaration isn’t a prototype
5587527.c:22:10: error: return type of ‘main’ is not ‘int’
5587527.c: In function ‘main’:
5587527.c:22:10: error: old-style function definition
5587527.c:29:9: error: implicit declaration of function ‘strcmpi’
5587527.c:29:9: error: nested extern declaration of ‘strcmpi’
5587527.c:35:15: error: ‘struct agenda’ has no member named ‘mail’
5587527.c:36:9: error: implicit declaration of function ‘creacola’
5587527.c:36:9: error: nested extern declaration of ‘creacola’
5587527.c:36:12: error: assignment makes pointer from integer without a cast
5587527.c:41:5: error: implicit declaration of function ‘colavacia’
5587527.c:41:5: error: nested extern declaration of ‘colavacia’
5587527.c:43:5: error: implicit declaration of function ‘getch’
5587527.c:43:5: error: nested extern declaration of ‘getch’
5587527.c: At top level:
5587527.c:48:18: error: function declaration isn’t a prototype
5587527.c: In function ‘nuevonodo’:
5587527.c:48:18: error: old-style function definition
5587527.c:51:40: error: ‘struc’ undeclared (first use in this function)
5587527.c:51:40: note: each undeclared identifier is reported only once for each function it appears in
5587527.c:51:46: error: expected ‘)’ before ‘nodo’
5587527.c: At top level:
5587527.c:61:18: error: conflicting types for ‘creacola’
5587527.c:36:13: note: previous implicit declaration of ‘creacola’ was here
5587527.c: In function ‘creacola’:
5587527.c:65:11: error: ‘P’ undeclared (first use in this function)
5587527.c: In function ‘mostrar’:
5587527.c:85:54: error: ‘struct agenda’ has no member named ‘mail’

Я добавил ; в строки 10, 14, 16, 17 и повторил попытку

cc1: warnings being treated as errors
5587527.c:22:10: error: function declaration isn’t a prototype
5587527.c:22:10: error: return type of ‘main’ is not ‘int’
5587527.c: In function ‘main’:
5587527.c:22:10: error: old-style function definition
5587527.c:29:9: error: implicit declaration of function ‘strcmpi’
5587527.c:29:9: error: nested extern declaration of ‘strcmpi’
5587527.c:35:15: error: ‘struct agenda’ has no member named ‘mail’
5587527.c:43:5: error: implicit declaration of function ‘getch’
5587527.c:43:5: error: nested extern declaration of ‘getch’
5587527.c: At top level:
5587527.c:48:18: error: function declaration isn’t a prototype
5587527.c:48:18: error: ‘nuevonodo’ redeclared as different kind of symbol
5587527.c:16:18: note: previous declaration of ‘nuevonodo’ was here
5587527.c: In function ‘nuevonodo’:
5587527.c:48:18: error: old-style function definition
5587527.c:51:40: error: ‘struc’ undeclared (first use in this function)
5587527.c:51:40: note: each undeclared identifier is reported only once for each function it appears in
5587527.c:51:46: error: expected ‘)’ before ‘nodo’
5587527.c: In function ‘creacola’:
5587527.c:65:11: error: ‘P’ undeclared (first use in this function)
5587527.c: In function ‘mostrar’:
5587527.c:85:54: error: ‘struct agenda’ has no member named ‘mail’

Исправить main в строке 22 (до int main(void))

5587527.c: In function ‘main’:
5587527.c:29:9: error: implicit declaration of function ‘strcmpi’
5587527.c:29:9: error: nested extern declaration of ‘strcmpi’
5587527.c:35:15: error: ‘struct agenda’ has no member named ‘mail’
5587527.c:43:5: error: implicit declaration of function ‘getch’
5587527.c:43:5: error: nested extern declaration of ‘getch’
5587527.c: At top level:
5587527.c:48:18: error: function declaration isn’t a prototype
5587527.c:48:18: error: ‘nuevonodo’ redeclared as different kind of symbol
5587527.c:16:18: note: previous declaration of ‘nuevonodo’ was here
5587527.c: In function ‘nuevonodo’:
5587527.c:48:18: error: old-style function definition
5587527.c:51:40: error: ‘struc’ undeclared (first use in this function)
5587527.c:51:40: note: each undeclared identifier is reported only once for each function it appears in
5587527.c:51:46: error: expected ‘)’ before ‘nodo’
5587527.c: In function ‘creacola’:
5587527.c:65:11: error: ‘P’ undeclared (first use in this function)
5587527.c: In function ‘mostrar’:
5587527.c:85:54: error: ‘struct agenda’ has no member named ‘mail’

Изменено strcmpi в строке 29 на strcmp

5587527.c: In function ‘main’:
5587527.c:35:15: error: ‘struct agenda’ has no member named ‘mail’
cc1: warnings being treated as errors
5587527.c:43:5: error: implicit declaration of function ‘getch’
5587527.c:43:5: error: nested extern declaration of ‘getch’
5587527.c: At top level:
5587527.c:48:18: error: function declaration isn’t a prototype
5587527.c:48:18: error: ‘nuevonodo’ redeclared as different kind of symbol
5587527.c:16:18: note: previous declaration of ‘nuevonodo’ was here
5587527.c: In function ‘nuevonodo’:
5587527.c:48:18: error: old-style function definition
5587527.c:51:40: error: ‘struc’ undeclared (first use in this function)
5587527.c:51:40: note: each undeclared identifier is reported only once for each function it appears in
5587527.c:51:46: error: expected ‘)’ before ‘nodo’
5587527.c: In function ‘creacola’:
5587527.c:65:11: error: ‘P’ undeclared (first use in this function)
5587527.c: In function ‘mostrar’:
5587527.c:85:54: error: ‘struct agenda’ has no member named ‘mail’

... Я сделал несколько правильных ошибок / перекомпилировал / получил больше ошибок для вас. Теперь твоя очередь.

3 голосов
/ 08 апреля 2011

Вы должны завершить определение struct точкой с запятой:

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

Аналогично для объявлений переменных и функций:

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

И Возвращаемое значение main имеет тип int.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...