www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - How can I restrict the cursor not to go further...?

↑ ↓ ← Alexandar <Alexandar_member pathlink.com> writes:
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
↑ ↓ Bertel Brander <bertel post4.tele.dk> writes:
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 <bertel post4.tele.dk> writes:
Bertel Brander wrote:
 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.


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 - Bertel
Mar 17 2006