creating a get customer name function

i'm trying to create a function to have someone input their name in this format:
lastname, firstname
basically at this point i use a getch() to get each letter, cout the letter on the screen, and wait until the user enters a ',' in which case it'll break the loop. but for some reason it's completely not working :(
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
void Customer::getCustomerName()
{
    char input;
    char* pointer;
    int l=0, f=0;

    pointer = &input;

    cout << "Customers Name: ";
    do
    {
        input = _getch();
        cout << input;
        if(input = ',')
        {
            lastName[l] = '\0';
            break;
        }
        lastName[l] = *pointer;
        l++;
    }while(1);
    cin.ignore(2, ' ');
    do
    {
        input = _getch();
        if(input = '\n')
        {
            firstName[f] = '\0';
            break;
        }
        cout << input;
        firstName[f] = *pointer;
        f++;
    }while(1);
    return;
}
Why don't you just read the entire line of input into a std::string and then parse the input? You can do something like this:
1
2
std::string name;
getline(std::cin, name);


I'd recommend using the substr() function to read the parts that you want.
Topic archived. No new replies allowed.