Two dimensional char array

Jul 20, 2012 at 4:10pm
I am trying to write a program which will ask the user how many names they want to enter and then it will allow them to enter that many names. My problem is the output looks like this.

How many names?: 3
Name: Name: name1
Name: name2
Name: name3


And this is the piece of code.
1
2
3
4
5
6
7
8
    cout << "How many names?: ";
    cin >> numNames;
    
    for(int k = 0; k < numNames; k++)
	{
		cout << "Name: ";
		cin.getline(names[k],MAX_LENGTH);
	}


Just some advice on what i'm doing wrong would be great. Thanks in advance.
Jul 20, 2012 at 4:29pm
After entering a number you can use std::cin.ignore() to skip the new line character placed in the input buffer by the input.
Jul 20, 2012 at 4:33pm
Exactly what I was looking for, thank you very much.
Topic archived. No new replies allowed.