structure pointers

This is a discussion on structure pointers within the C Programming forums, part of the General Programming Boards category; Why does'nt this code work I know functions must know about things before they can use them, I thought the ...

  1. #1
    Unregistered
    Guest

    structure pointers

    Why does'nt this code work I know functions must know about things before they can use them, I thought the prototype did that guess not.

    #include<stdio.h>
    #include<conio.h>

    void details1(struct baby *kayleigh_ptr);

    int main()
    {

    struct baby{
    int age;
    char name[10];
    };


    struct baby kayleigh;
    struct baby *kayleigh_ptr=&kayleigh;


    details1(kayleigh_ptr);
    getch();

    return 0;
    }

    void detail1(struct baby *kayleigh_ptr)
    {
    kayleigh_ptr->age=10;
    }


    thanks leaner(wanting to ba master).

  2. #2
    Unregistered
    Guest
    I moved

    struct baby{
    int age;
    char name[10];
    };

    outside main before the function prototype (so that the structure is global to all functions instead of local to main),
    The code then compiled and ran, although it doesn't really do much. Hope that helps!

  3. #3
    Unregistered
    Guest
    Oh forgot: also need to make prototype match function (detail1 != details1).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generic Pointers to structures
    By dunxton in forum C Programming
    Replies: 8
    Last Post: 02-20-2009, 10:23 AM
  2. sorting structure members using pointers
    By robstr12 in forum C Programming
    Replies: 5
    Last Post: 07-25-2005, 06:50 PM
  3. Structure Within Structure
    By Shakira in forum C Programming
    Replies: 3
    Last Post: 11-04-2003, 03:35 PM
  4. How To Detect Pointers In Structure
    By GaPe in forum C Programming
    Replies: 8
    Last Post: 07-31-2003, 05:12 PM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21