Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Swaroop

Status
Not open for further replies.

swaroop

Programmer
Feb 4, 2001
100
US
How can I use ignore() and truncate to take 20 char from user input in a name[40] variable.....

When I try to use

cin.get(name,20,'\n');
cin.getline(name,20,'\n');


cin.get(name,20,'\n').get();
cin.getline(name,20,'\n').get();

cin.get(name,20,'\n').ignore(20);
cin.getline(name,20,'\n').ignore(20);

It is not cleaning buffer in while loop.

Thanks in advance
 
what u could do is, use getchar() and get a single char ina while loop(checking for the limit, 20 in this case) and as and when u get it add it to the array of char.

i dont know if this is what u want.
 
Also, after the count of 20 is over, you can flush the buffer using function fflush and then break the while loop.

Yateen..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top