Hey guys, I really need your help on this, because I'm either being really dizzy or I just can't figure out why my code isn't working at all.
I've wasted around 4 hours trying to turn around this problem so far and I just can't.

here is the part of the code responsible for all my frustraion:

cout<<"Name:"<<endl;                    
       fgets(name,256,stdin);
            cout<<"Phone:"<<endl;
            cin>>phone;

I need to use fgets because if I use the standard cin for my char name[257], it will end after the first whitespace typed and I don't want that.

The line Name: is automaticaly skipped and the result is this:

Name:
Phone:
(waiting for input)

If you know any alternative for this I would be really happy.

Recommended Answers

All 2 Replies

if it helps I've also tried this method and got the same problem

cout<<"Name:"<<endl;                    
       std::getline(std::cin, name);
cout<<"Phone:"<<endl;
            cin>>phone;

Try

cout<<"Name:"<<endl;                    
    std::getline(std::cin, name);
    cout<<"Phone:"<<endl;
    std::getline(std::cin, phone);

Mixing line inputs (fgets/getline) with cin is causing problems because they both do things differently. cin is leaving the input stream dirty (stuff left in the buffer you aren't expecting).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.