easy array of pointers question

This is a discussion on easy array of pointers question within the C++ Programming forums, part of the General Programming Boards category; Code: char* names[] = { {"Mark"}, {"Nikki"} }; char letter = *names[0]; char letter2 = *names[1]; cout << letter << ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    84

    easy array of pointers question

    Code:
    	char* names[] = 
    
    	{
    		{"Mark"},
    		{"Nikki"}
    	};
    
    	char letter = *names[0];
                    char letter2 = *names[1];
    	cout << letter << endl;
                    cout << letter2 << endl;
    I am trying to program a simple function that will sort out an array of names alphabeticaly . The above doesnt work . What i want to be able to do is store the 1st letter of both the names Mark and Nikki into separate chars then compare them . I have experimented a fair bit but i cant seem to get the ()'s and * in the right place .

    Any one get me?
    Last edited by The Gweech; 08-18-2003 at 03:02 PM.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    162
    I think your decalaration is right, but
    CODE]char letter = *names[1][/CODE]
    makes no sense. You haven't specified what char you want to give letter. If you want to do the M in Mark, then do
    Code:
    char letter= names[0][0]
    I guess that would work, though I haven't worked with pointers and arrays in a long time.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    84
    Thanks Salem .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array of Pointers to Arrays
    By Biozero in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 02:31 PM
  2. Replies: 4
    Last Post: 11-02-2006, 10:41 AM
  3. Creating an array of pointers to int[]
    By OkashiiKen in forum C Programming
    Replies: 3
    Last Post: 09-29-2006, 06:48 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  5. array of pointers to structs
    By stumon in forum C Programming
    Replies: 7
    Last Post: 03-24-2003, 06:13 AM

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