Thread: structures

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    28

    Question structures

    Ok I am learning how to pass structures to a function and I keep getting an error about return type of main is not int, and it does not display the name.

    I am following along in the book that I have, and this program is almost just like one they have in there. I don't really understand what I am doing wrong. Here is my code

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
     
    
    struct player {
        char name[20];
        int skill;
    };
    
    void pstruct(struct player profile);
        
    void main()
    {
        struct player info;
      
        strcpy(info.name,"Vertex");
        
        pstruct(info);
        
        system("pause");
    }
    
    void pstruct(struct player profile)
    {
        printf("%s\n",profile.name);
    }

  2. #2
    Registered User
    Join Date
    Oct 2004
    Posts
    120
    Or, disregard my crap and look at your main function. The compiler tells you exactly whats wrong. And Salem will come along in a little bit and drive it into your nogging exactly whats wrong with his BFG
    Last edited by pablo615; 10-12-2004 at 04:48 PM.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    28
    Man this is driving me nuts lol, its probably really obvious too!

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    120
    Like I said in my post above, the compiler is telling you EXACTLY what is wrong. I am assuming of course that you are experienced enough to know what a return type is and what an int is and how to define a function. If thats not the case, then maybe the compiler error isn't as helpful to you as it is to me

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Here is another hint:
    Code:
    void main()
    {
       // code here
    }
    The above code is incorrect, that is NOT the way you declare main(). If you read the FAQ, it will tell you the correct way.

  7. #7
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    after you fix the code, take the book that had that example and throw it in the garbage... better yet, burn it...

  8. #8
    Registered User
    Join Date
    Nov 2003
    Posts
    28
    Ok thanks for the reference to the faq Hammer, I understand why not to do that now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-05-2006, 11:06 PM
  3. Input output with structures
    By barim in forum C Programming
    Replies: 10
    Last Post: 04-27-2004, 08:00 PM
  4. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM