Issue assigning characters into character array

Hi all,

I'm trying to sort out how I can get user-entered data into a character array without.

Would using getline be a better approach?

I understand making the array's string type would be easier, however it's necessary that they stay character array's.

Here's my code:

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

//MAX_SIZE is a const int set to 100.

void input(char first[], char middle[], char last[])
{
    cout<<"Please input your first name: "<<endl;
    cin>>first[MAX_SIZE];
    cout<<"Please input your middle name: "<<endl;
    cin>>middle[MAX_SIZE];
    cout<<"Please input your last name: "<<endl;
    cin>>last[MAX_SIZE];

    
    //This is just a check to ensure the array was stored correctly
    for (int i=0; i<MAX_SIZE; i++)
        cout<<first[i];

    return;
}


EDIT: Solved it on my own :D
Last edited on
Topic archived. No new replies allowed.