I'm trying to make a 2D Array with pointers, where the first array is a list of X pointers (decided by the user at runtime, and each pointer points to a different array of Y characters, entered by the user
Then I need to manipulate the array of pointers so that when displayed, the character Arrays are displayed in alphabetic order. (AKA "Andrea", "Billy", "Bob", "Tera", "Treven", "Willy", etc.)
I'm less worried about the putting in alphabetic order, and more having trouble figuring out how to let the 2D array to be manipulated, in that each character entered is only one element in the array, which can be displayed consecutively like a string while stopping at the end of string mark, individually checked (so as to allow sorting for each letter), and how to use the pointers in the first array to call the second array and alter it.
...
Maybe I just need an easy-to-understand explaination of how pointers, pointer arrays, and arrays of pointers work, and how they are used, cus I'm so confused that I don't even know exactly what I need help with..
here's some snippets of the code I'm trying to work out, if it helps describe my problem.
the Array:
Expand|Select|Wrap|Line Numbers
- Array = new char * [NumEntries]; //array of row pointers
- for (int i = 0; i < NumEntries; i++)
- Array [i] = new char [Length+1];
Expand|Select|Wrap|Line Numbers
- int TakeInput (char **Array, int NumEntries, int Length)
- {
- char Input;
- int CurrCount (0);
- for (int i = 0; i < NumEntries; i++)
- {
- cout << "Enter Name: " << i+1;
- while ((Input = cin.get ()) != '\n')
- {
- Array [i][CurrCount] = Input;
- CurrCount++;
- if (CurrCount >= Length)
- break;
- else;
- }
- Array [i][CurrCount+1] = '\0';
- cout << endl;
- }
- return **Array;
- }
Expand|Select|Wrap|Line Numbers
- void Display (char **Array, int NumEntries)
- {
- for (int i = 0; i < NumEntries; i++)
- {
- for (char j = 0; j != '\n'; j++)
- cout << Array [i][j];
- }
- }
Expand|Select|Wrap|Line Numbers
- for (int i = 0; i <= EndCount; i++)
- for (int j = 0; j <= Length; j++)
- {
- if ((Array [i][j]) > (Array [i + 1][j]))
- {
- Temp = Array [i];
- Array [i] = Array [i+1];
- Array [i+1] = Temp;
- Swapped = true;
- }
- else;