So as you already know im still on my final assignment project and is it possible to limit the amount of digits a user can enter?
5 replies to this topic
#1
Posted 09 April 2011 - 06:53 AM
PePe===> BLACKSPADE EMPIRE<===PePe
www.blackspade-ent.com
www.blackspade-ent.com
|
|
|
#2
Posted 09 April 2011 - 09:43 AM
Nope, it's impossible.
Kidding aside what is it you were doing?
Kidding aside what is it you were doing?
#3
Posted 09 April 2011 - 09:49 AM
lol lets say i want the user to enter a 7 digit number. lets say he enter 8.... its suppose to prompt him saying you entered too many numbers.. i know how to do this with a if statement and single characters but not with entire numbers
PePe===> BLACKSPADE EMPIRE<===PePe
www.blackspade-ent.com
www.blackspade-ent.com
#4
Posted 09 April 2011 - 11:02 AM
Well, if it's an int, you can just compare it to 10000000
#5
Posted 09 April 2011 - 11:10 AM
Things in life can be so simple lol
PePe===> BLACKSPADE EMPIRE<===PePe
www.blackspade-ent.com
www.blackspade-ent.com
#6
Posted 09 April 2011 - 11:25 AM
teensicle said:
...lets say i want the user to enter a 7 digit number. lets say he enter 8.... its suppose to prompt him saying you entered too many numbers..
First, show a code example of what you have so far.
You could do this with a simple array, like:
char ch;
char MyArray[10];
int i, count = 10;
i = 0;
while(i < count)
{
ch = getche();
if((ch > 31) && (ch < 127)) /* ascii chars */
{
MyArray[i] = ch;
i++;
}
else if((ch == 8) && (i > 0)) /* backspace */
{
MyArray[i] = '\0';
i--;
}
}
MyArray[count] = '\0';
if(i >= 7) /* here is where you test for a valid count */
{
printf("you entered too many numbers\n");
}
At the end of user input, a test is made to verify the character count is correct.*Code not tested, but, the general principle is there.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









