Thread: Need help on structure

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    40

    Need help on structure

    Hello,

    I am writing a grade management program. I have a structure but I keep getting an error.

    struct grades
    {
    char students[30];
    int grade1;
    int grade2;
    int grade3;
    }

    struct grades name[30], g1, g2, g3,*gptr;

    Here is the error:

    grades.c:25: two or more data types in declaration of `name'
    grades.c:25: two or more data types in declaration of `g1'
    grades.c:25: two or more data types in declaration of `g2'
    grades.c:25: two or more data types in declaration of `g3'
    grades.c:25: two or more data types in declaration of `gptr'

    could someone help me with this please.. I am so new to C that I don't know what it means... I have exhausted all other resources..

    Thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1) Go read the forum Announcements, and then use code tags for all future code postings.

    2) Is this a copy/paste of the actual code? If so:
    Code:
     struct grades
    {
    char students[30];
    int grade1;
    int grade2;
    int grade3;
    };
    
    struct grades name[30], g1, g2, g3,*gptr;
    You were missing a ; there.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Quote Originally Posted by tameeyore
    struct grades name[30], g1, g2, g3,*gptr;
    Is that some funky C way of declaring a new object or what? I've never seen something like that...

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    It's just declaring more than one variable. The same way you can do int a, b, c, *ptr;
    If you understand what you're doing, you're not learning anything.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    To be precise, it's an array of 30 structures, plus 3 individual ones, and a pointer to a structure.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Feb 2005
    Posts
    24

    the same to you

    just like you say i think it is not engh space to hold it
    you miss the " ;"

  7. #7
    ---
    Join Date
    May 2004
    Posts
    1,379
    enough space to hold what?

  8. #8
    Registered User
    Join Date
    Feb 2005
    Posts
    24
    sorry ! i make a mistake!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem referencing structure elements by pointer
    By trillianjedi in forum C Programming
    Replies: 19
    Last Post: 06-13-2008, 05:46 PM
  2. Replies: 5
    Last Post: 02-14-2006, 09:04 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  5. C structure within structure problem, need help
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-30-2001, 05:48 PM