Thread overview
How can I restrict the cursor not to go further...?
Mar 17, 2006
Alexandar
Mar 17, 2006
Bertel Brander
[BUG] Re: How can I restrict the cursor not to go further...?
Mar 18, 2006
Bertel Brander
March 17, 2006
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


March 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
March 18, 2006
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