0

I was just asking, is it also possible to define 2D arrays? If so, how do I pass them into the functions and use them in an address book? As in can I say employee.name[x][] when I use things like strcmp, puts, or gets, or must i say employee.name[x]?

2
Contributors
1
Reply
3
Views
9 Years
Discussion Span
Last Post by Narue
0

>is it also possible to define 2D arrays?
Yes.

>how do I pass them into the functions
Just like passing any other type, you match the declaration:

void foo ( int a[2][5] );

int main()
{
  int a[2][5];

  foo ( a );
}

There are variations, of course, but this is by far the easiest guideline to remember.

>As in can I say employee.name[x][] when I use things
>like strcmp, puts, or gets, or must i say employee.name[x]?
Ultimately, you must pass the correct type. If you have an array defined like so:

char a[10][20];

You still need to pass a pointer to char to puts (for example):

puts ( a[x] );

A 2D array is nothing more than an array of arrays. Keep that in mind when working with them.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.