Help with 2 dimensional char arrays

I have this assignment and I was hoping someone could give me an example on how to do it. please!! Thank You!! Any help is greatly appreciated.

Simple e-­‐mail address finder. Using the data below in a 2 dimensional character array create an e-­‐mail address finder that ignores case of the input string and returns the e-­‐mail address of the person listed. If the name is not listed, return an appropriate error message.

“Barack”,president@whitehouse.gov,
“Roger”,“rpowell@valleycollege.edu”,
“Mark”,”markz@facebook.com”,
“Bill”,”billg@microsoft.com”,
“Gaga”,”admin@lady-­‐gaga.net”,
You say that it has to be a 2D character array, is 2D char * OK?
Here is one way you might do it.
You want to create a 2D array of char * that look like:

        +--------------------> "Barack"       
        |         +-------> "president@whitehouse.gov"
    ----|---------|----
   | char *  | char *  |    
    -------------------
   | char *  | char *  |
    -------------------
   | char *  | char *  |
    -------------------
   | char *  | char *  |
    -------------------
   | char *  | char *  |
    ----|---------|----
        |         +--------> "Gaga"
        +-----------------> "admin@lady-gaga.net"

Each row is an entry in your address book. The first column is
there name and the second column is there email address.

Read in the name you want to search for and then search the
first column in each row the that name. Use strcasecmp to
compare and ignore case.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

/*
 * 
 */
#define NAME 5
#define EMAIL 2
int main() {

   
    
    
    char* address[NAME][EMAIL] = {{"Barrack", "president@whitehouse.gov"},
                         {"Roger", "rpowell@valleycollege.edu"},
                         {"Mark", "markz@facebook.com"},
                         {"Bill", "billg@microsoft.com"},
                         {"Gaga", "admin@lady-gaga.net"}};
    
    for(int i = 0; i < NAME; i++) {
        for(int j = 0; j < EMAIL; j++) {
            cout << address[i][j] << endl;
           
        }
    }
        
        
    
        
    
   
    return 0;
}

I can't seem to know how to do the searching part, but this displays everything in the 2d char* array
Topic archived. No new replies allowed.