-
February 28th, 2011, 02:23 PM
#1
How to Stop input?
Hello my friends i've one question:
i want to stop the input of an user, when he inserts a certain string es "x". Now this part of code:
Code:
char * risposte [dim];
for (int i=0;i<dim;i++)
risposte[i]=new char [dim];
int contarisp=0;
cout<<"Inserisci le risposte del cruciverba (max 30). Usa il carattere terminatore 'x' per finire l'immissione di parole.\n";
cin>>risposte[contarisp];
while(strcmp(risposte[contarisp],"x"))
{
cout<<"Hai inserito "<<risposte[contarisp]<<endl;
cout<<"Conta risp è "<<contarisp<<endl;
contarisp++;
cout<<"ora è "<<contarisp<<endl;
cin>>risposte[contarisp];
}
doesn't always work why? How i can stop the "While"?
Last edited by Falko-tux; February 28th, 2011 at 02:27 PM.
-
February 28th, 2011, 03:03 PM
#2
Re: How to Stop input?
What is your intent with this:
Code:
char * risposte [dim];
for (int i=0;i<dim;i++)
risposte[i]=new char [dim];
Viggy
-
March 1st, 2011, 02:57 AM
#3
Re: How to Stop input?
Originally Posted by Falko-tux
i want to stop the input of an user
You can't using standard C++. All you can do is "ask for some input" and wait till the user/os to return control to your code, with input in your buffer.
From there, you can choose to ask for more input, or to do something else, but it is not possible to interrupt the user when he inserts a specific character, for example (again, using standard C++).
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
-
March 1st, 2011, 06:05 AM
#4
Re: How to Stop input?
It's an array of pointers, and then I create a new char [] for each position of the previous array.
-
March 1st, 2011, 06:07 AM
#5
Re: How to Stop input?
Thank you, so I have to say the max number of inputs the user can write, right?
-
March 1st, 2011, 11:16 AM
#6
Re: How to Stop input?
Been lookin' at code too long... I missed the '[dim]' part! D'OH!
When does the check not work?
Viggy
-
March 1st, 2011, 12:00 PM
#7
Re: How to Stop input?
it doesn't work when I put the "x" string..it must stop but it waits for other strings!
-
March 1st, 2011, 12:23 PM
#8
Re: How to Stop input?
I don't see a check to see if you've overrun the array...
Viggy
-
March 1st, 2011, 02:29 PM
#9
Re: How to Stop input?
I tried to print the array, but it doesn't arrive there so I put some cout after the cin in the while but the program when I insert "x" seems to 'freeze' and waits for other input!
-
March 1st, 2011, 03:13 PM
#10
Re: How to Stop input?
What are you doing after the while loop?
Viggy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|