Thread: passing structure to function

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    46

    passing structure to function

    Anyone know why I can't pass the structure to the function this way????

    Code:
    #include <stdio.h>
    #include <string.h>
    
    
    void diplay_jock(athlete players) {
    
    
    printf("%s %s is ranked %d and earns %.2f\n", players.last_name, players.first_name, players.rank, players.salary);
    
    }
    
    	
    
    int main (void) {
    
    
      struct athlete {
      char last_name[25];
      char first_name [20];
      int rank;
      float salary;
    } players = {"Kloc", "Daniel", 2, 100000};
    
    display_jock(players);
    
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Jul 2011
    Posts
    46
    hhmmmm i changed function name and worked, now i changed function name back and works again? wtf? i'm using cygwin, is there a bug?

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You should define the struct before you define the function.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    move lines 17 to 22 to start at line 4

  5. #5
    Registered User
    Join Date
    Jul 2011
    Posts
    46
    yep got it. tks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing Function to Structure
    By C-bob in forum C Programming
    Replies: 11
    Last Post: 07-22-2011, 07:36 PM
  2. passing pointer to a structure in a function
    By steve1_rm in forum C Programming
    Replies: 5
    Last Post: 02-03-2008, 02:48 AM
  3. Passing structure field to function
    By Lude in forum C Programming
    Replies: 5
    Last Post: 01-18-2008, 03:45 PM
  4. Passing structure to function
    By Sereby in forum C Programming
    Replies: 4
    Last Post: 07-28-2004, 10:05 PM
  5. Passing a structure to a function?
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2001, 04:28 AM