Thread: pass structure to function

  1. #16
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Yes, I was referring to your post where you mentioned that sizeof on a function parameter that is a pointer won't work.

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,653
    Yes, to avoid confusing, the sizeof should be applied BEFORE the function and the size (or elements) passed TO the function since it cannot determine the size.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    Oct 2006
    Posts
    32
    if this is what your talking about, it did what i wanted it to do.. or so ithink it did
    Code:
    length = strlen(rec->pass_name);
         for( i = 0; i < length; i++ )
          printf( "Seat [%i] is assigned to %s \n\n",  rec[ i ].seat_number , rec[ i ].pass_name );
    Code:
    Seat [21] is assigned to DR Power
    Seat [2] is assigned to Green Lantern
    Seat [30] is assigned to The Flash
    Seat [7] is assigned to Super Girl
    Seat [12] is assigned to Phoenix
    Seat [17] is assigned to Clark Kent
    Seat [4] is assigned to The Tick
    Seat [26] is assigned to Swamp Thing
    i am aware that i went about this whole project if you will the wrong way.. i think i set up the struct wrong to begin with..
    thx
    everyone

  4. #19
    Registered User
    Join Date
    Oct 2006
    Posts
    32
    is this what you wanted? is this better than
    length = strlen(rec->pass_name);

    Code:
    struct fast_line record[] = {    /** fill seats wth passengers **/
            { "DR Power", 21 },
            { "Green Lantern", 2 },
            { "The Flash" , 30 },
            { "Super Girl" , 7 },
            { "Phoenix", 12 },
            { "Clark Kent", 17 },
            { "The Tick" ,4 },
            { "Swamp Thing" , 26 }
            
              };
    
    size_t count = (record, sizeof(record) / sizeof * record );
    show_seats_taken (record, count );
    
    
    void show_seats_taken( struct fast_line *rec,  size_t size )
    {
     int i, length;
     //char temp[BUFSIZ];
     
    // length = strlen(rec->pass_name);
         for( i = 0; i < size; i++ )
          printf( "Seat [%i] is assigned to %s \n\n",  rec[ i ].seat_number , rec[ i ].pass_name );
         
         
         }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Passing a structure to a function?
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2001, 04:28 AM