Thread: Struct errors

  1. #1
    Registered User
    Join Date
    Jun 2019
    Posts
    1

    Struct errors

    hi i am new to c programming, having issue ith struct.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    typedef struct = {
        const char *name;
        const char *species;
        int teeth;
        int age;
    }fish;
    void catalog(struct fish f)
    {
        printf("%s is a %s with %i teeth. He is %i\n", f.name, f.species, f.teeth, f.age);
    }
    
    int main ()
    {
                fish snappy = { "Snappy", "Piranha", 69, 14 };
            catalog(snappy);
            return 0;
    }
    But when i compile it, it gives me this error

    Code:
    fish.c:4:16: error: expected ‘{’ before ‘=’ token
    fish.c:9:2: warning: data definition has no type or storage class [enabled by default]
    fish.c:10:21: warning: ‘struct fish’ declared inside parameter list [enabled by default]
    fish.c:10:21: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
    fish.c:10:26: error: parameter 1 (‘f’) has incomplete type
    fish.c: In function ‘main’:
    fish.c:17:15: error: expected ‘;’ before ‘snappy’
    fish.c:18:11: error: ‘snappy’ undeclared (first use in this function)
    fish.c:18:11: note: each undeclared identifier is reported only once for each function it appears in

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    There is no = on line 4.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2019
    Posts
    1
    Hello balushyno1,

    1) Remove '=' from line 4
    2) Remove 'struct' keyword from line 10, since you have already typedef structure as 'fish', so there is no need to use it again. Only "voidcatalog(fish f)" would be enough.

    You can solve such errors easily by looking closely at the compile logs. Best of Luck.

    Best Regards,
    Jaspreet

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors with struct and I/O
    By Gil Carvalho in forum C Programming
    Replies: 89
    Last Post: 05-12-2012, 07:22 AM
  2. Replies: 11
    Last Post: 03-06-2011, 09:12 PM
  3. Making a (atom) class in a (struct) class makes big errors!
    By Yarin in forum Windows Programming
    Replies: 4
    Last Post: 09-11-2007, 07:18 PM
  4. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  5. Struct errors...
    By Cale in forum C Programming
    Replies: 2
    Last Post: 12-12-2002, 11:49 PM

Tags for this Thread