c++ - How can I restrict the cursor not to go further...?
- Alexandar (5/5) Mar 17 2006 How can I restrict the cursor not to go further...i.e. when I carry out ...
-
Bertel Brander
(21/25)
Mar 17 2006
#include
- Bertel Brander (23/31) Mar 17 2006 As a side note; one might think that this should do the trick:
How can I restrict the cursor not to go further...i.e. when I carry out the program and the program waits for numbers or chars isertion, I want to allow just a determined number (for instance 4) of digits or chars to be entered. It won't allow me to enter the fifth char and will wait for ENTER. Thank you in advance, Alexandar
Mar 17 2006
Alexandar wrote:How can I restrict the cursor not to go further...i.e. when I carry out the program and the program waits for numbers or chars isertion, I want to allow just a determined number (for instance 4) of digits or chars to be entered. It won't allow me to enter the fifth char and will wait for ENTER.#include <stdio.h> #include <conio.h> int main() { char Text[5]; int i; for(i = 0; i < 4; i++) { Text[i] = getch(); putch(Text[i]); } Text[i] = 0; while(getch() != 13) ; printf("\nYou entered: %s\n", Text); } -- Absolutely not the best homepage on the net: http://home20.inet.tele.dk/midgaard But it's mine - Bertel
Mar 17 2006
Bertel Brander wrote:Alexandar wrote:As a side note; one might think that this should do the trick: #include <stdio.h> #include <conio.h> int main() { char Text[5]; int i; for(i = 0; i < 4; i++) { Text[i] = getche(); } Text[i] = 0; while(getch() != 13) ; printf("\nYou entered: %s\n", Text); } But it does not, all the characteres entered are echoed on screen, but only 4 put into Text, as if both getch's was getche. -- Absolutely not the best homepage on the net: http://home20.inet.tele.dk/midgaard But it's mine - BertelHow can I restrict the cursor not to go further...i.e. when I carry out the program and the program waits for numbers or chars isertion, I want to allow just a determined number (for instance 4) of digits or chars to be entered. It won't allow me to enter the fifth char and will wait for ENTER.
Mar 17 2006