# Thread: 2 dimensional array asking for number of names and the name

1. ## 2 dimensional array asking for number of names and the name

hi im your typical noob to C programming and am asking for some help on a recent program im working on for my intro to C class.

in my program i have to enter payroll information for employees and my professor wants us to use a 2-dimensional array to count for the number of employees and the amount of letters in their name.

so right now if i have this:

Code:
```char emp_name[30][10];

/* Welcome and prompt for number of employees */
printf ("Enter the number of employees (1-10): ");
scanf ("%i", &emp_name[30][10]);
printf ("\n");```
how would i use the char emp_name[30][10] to count for the number of employees, and then later use that to prompt for that users name?

thank you for any help

2. I'm curious... why do you think this will work?
scanf ("%i", &emp_name[30][10]);

3. i have no idea. i know it wont work lets put it at that. just trying to give an idea of what i am looking to do.

basically i want to ask the user for how many names they want to enter between 1 and 10 and then later ask for the name for the number of names entered with a max of 30 characters.

im lost.

4. the professor gave us the algorithm for the code we are suppose to write and only gave emp_name[30][10] and not like just an int to count for the number of employees. so im figuring he wants us to use the multidimensional array to count for the number of employees.

5. I figure he wants you to use the 2D array to store the employee names.
A name consists of several characters, so to store a name, you would need several characters, a string, as it is called.

char [x] = string

So if we then would need to store several names, then we would need an array of strings, no?
That would be something like

string [y]

And since string = char [x], that becomes

char [y][x]

You need to create more variables to store other things.

6. yep, i see where i am making my mistake the [10] part of emp_name is just to count for the maximum of the 10 names that can be entered, but i would need another variable like int num_emp to count for the number of employees actually being entered and then pass that onto emp_name later in the code.

7. just need clarification about the max number of employees and characters that can be in their name; currently it is
Code:
`char emp_name[30][10];`
which means that you can have a max of 30 employees each having names no longer than 10 characters, is that right?

8. Originally Posted by itCbitC
just need clarification about the max number of employees and characters that can be in their name; currently it is
Code:
`char emp_name[30][10];`
which means that you can have a max of 30 employees each having names no longer than 10 characters, is that right?
Each having names no longer than 9 characters (or, if you like, strictly less than 10 characters), since one character must be set aside for \0.

9. Originally Posted by tabstop
Each having names no longer than 9 characters (or, if you like, strictly less than 10 characters), since one character must be set aside for \0.
I thought likewise, however the prompt below contradicts that as in.
Originally Posted by kisiellll
Code:
`printf ("Enter the number of employees (1-10): ");`
As it implies that there can be only 10 employess, so I was wondering if the array dimensions were switched around.