Identify blank line with gets() function!!
-
Hi I'd like to get the user's input from the console, if the user put in some text, this information will be put in a buffer, if the user type in nothing in and press enter then the program is terminated. But how do i know if the user has type in something??? i've attempted to play around with this, first with cin.getline, cin.get ...and finally come up with gets(), however it still seem has not done the job. this is the code that i've attempted
char input[MAX_PATH]; char *pInput = input; cout << "Enter the text " << endl;//prompt for the input char delimeter =(char)gets(input);//store what the user types while( delimeter != '\r' ) { // int length = strlen(input); cout << "Enter the text " << endl; delimeter =(char)gets(input); }
Any ideas, helps or suggestions are highly appreciated!!! Regard, -
Hi I'd like to get the user's input from the console, if the user put in some text, this information will be put in a buffer, if the user type in nothing in and press enter then the program is terminated. But how do i know if the user has type in something??? i've attempted to play around with this, first with cin.getline, cin.get ...and finally come up with gets(), however it still seem has not done the job. this is the code that i've attempted
char input[MAX_PATH]; char *pInput = input; cout << "Enter the text " << endl;//prompt for the input char delimeter =(char)gets(input);//store what the user types while( delimeter != '\r' ) { // int length = strlen(input); cout << "Enter the text " << endl; delimeter =(char)gets(input); }
Any ideas, helps or suggestions are highly appreciated!!! Regard,getchar
maybe what you need instead ofgets
. Roger Stewart "I Owe, I Owe, it's off to work I go..." -
Hi I'd like to get the user's input from the console, if the user put in some text, this information will be put in a buffer, if the user type in nothing in and press enter then the program is terminated. But how do i know if the user has type in something??? i've attempted to play around with this, first with cin.getline, cin.get ...and finally come up with gets(), however it still seem has not done the job. this is the code that i've attempted
char input[MAX_PATH]; char *pInput = input; cout << "Enter the text " << endl;//prompt for the input char delimeter =(char)gets(input);//store what the user types while( delimeter != '\r' ) { // int length = strlen(input); cout << "Enter the text " << endl; delimeter =(char)gets(input); }
Any ideas, helps or suggestions are highly appreciated!!! Regard,Try something like this:
char input[MAX_PATH];
do {
cout << "Enter the text " << endl;//prompt for the input gets(input);//store what the user types if (strlen(input) != 0) { // ... }
} while (strlen(input) != 0);
Gary R. Wheeler
-
Hi I'd like to get the user's input from the console, if the user put in some text, this information will be put in a buffer, if the user type in nothing in and press enter then the program is terminated. But how do i know if the user has type in something??? i've attempted to play around with this, first with cin.getline, cin.get ...and finally come up with gets(), however it still seem has not done the job. this is the code that i've attempted
char input[MAX_PATH]; char *pInput = input; cout << "Enter the text " << endl;//prompt for the input char delimeter =(char)gets(input);//store what the user types while( delimeter != '\r' ) { // int length = strlen(input); cout << "Enter the text " << endl; delimeter =(char)gets(input); }
Any ideas, helps or suggestions are highly appreciated!!! Regard,You may have problems mixing
cin
/cout
andgets
/printf
. For console hacks, I usegets
/printf
. /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com