structures and arrays

This is a discussion on structures and arrays within the C Programming forums, part of the General Programming Boards category; Ok this is my problem... #include <stdio.h> #define MAX [10] struct employee // structure of employees (first and last name) ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    8

    structures and arrays

    Ok this is my problem...


    #include <stdio.h>
    #define MAX [10]

    struct employee // structure of employees (first and last name)
    {
    char firstname [20];
    char lastname [20];
    };
    typepdef struct employee Employee;

    GetName (Employ *);

    Employee Employees [5]; //an array of the structure

    void main (){
    Employee E;
    GetName (&E); //Gets name from user

    //now how do i store that into the first spot the array
    //and once i do that how i can i call it again to store it into
    //a second spot
    }

    void GetName(employ *pE){
    printf ("please enter the first name of the employee");
    scanf ("%s", &(pE->firstname));
    printf ("please enter the coordinates for point 2 (x and y)");
    scanf ("%s", &(pE->lastname));
    }


    ????

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: structures and arrays

    >>void main ()
    Read this

    //now how do i store that into the first spot the array
    //and once i do that how i can i call it again to store it into
    //a second spot
    Maybe like this:

    Code:
    for (i = 0; i < 5; i++)
    {
      GetName(&E);
      Employees[i] = E;
    }
    But in this case, what's the point of the E struct? Might as well just use the one from the array.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with arrays structures sorting.
    By pitifulworm in forum C Programming
    Replies: 42
    Last Post: 02-09-2009, 11:31 AM
  2. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  3. errors with arrays and structures
    By ssjnamek in forum C++ Programming
    Replies: 4
    Last Post: 03-03-2002, 10:48 PM
  4. Newbie Help (Arrays, Structures, Functions,Pointers)
    By tegwin in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2002, 05:29 PM

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