1

throw me 3 errors when compiling I am using 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();
}
3
  • 6
    You should add the compile errors you're receiving from the compiler... Commented Apr 7, 2011 at 20:57
  • syntax error before "int" and I denotes the power fail: int colavacia(struct nodo *) Commented Apr 7, 2011 at 21:00
  • 1
    Don't EVER ever use gets(). NEVER!. Never say "never" ... except when telling people about gets(). With gets() it is impossible to code defensively and avoid buffer overflows. Use fgets() instead. fgets(x.telefono, sizeof x.telefono, stdin); Commented Apr 7, 2011 at 21:22

2 Answers 2

3

You must end a struct definition with a semicolon:

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

Similarly for variable and function declarations:

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

And the return value of main has type int.

Sign up to request clarification or add additional context in comments.

Comments

3
5587527.c:2:19: fatal error: conio.h: No such file or directory

I've commented out the offending #include and tried again

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’

I've added a ; to lines 10, 14, 16, 17 and tried again

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’

Fix main in line 22 (to 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’

Changed strcmpi in line 29 to 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’

... I've done a few correct errors / recompile / get more errors for you. Now it's your turn.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.