Array of chars - problem

Hello everyone!

I want to make a program that reads a few names and stores them in an array of char-pointers.
What I have until now:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>
#include<cstring>

using namespace std;

int main()
{
    char x[30];
    char *p [23];
    for(int i=1; i<=2; i++)
    {   p[i] = new char[100];
        cout<<"Name: ";
        cin.getline(p[i], 100);
    }


    for(int i=1; i<=2; i++)
    {
        cout<<p[i]<<" \n";
        delete[] p[i];
    }
}


In the code above I am reading those names and I store them in an array of char-pointers called p and I am printing those names on the screen.

But I want to manipulate every name before I will print them and I don't know how. So, I want to transform every element of that array (every p[i]) in an array of characters (x) so that when I execute cout<<x[0] to print the first character of a name (it doesn't matter which one). How can I do that?
Thanks!

L.E: I tried to write all those strings to a file and then to read them. I didn't succeded. Please help me.
Last edited on
In C++ pointers and arrays are in some ways closely related. Writing p[i][0] will access the first character of the i'th name.
Respectfully thank you, hamsterman.
Topic archived. No new replies allowed.