character validation

how do i validate against charcaters in c ta

Ruffenator,

I read your other post as well but I am not sure what you're asking...it isn't hard to validate values (x >=1 && x <=3, etc) so I am not sure what you're really asking.

You probably want to put up some code for us to help you or explain better? You are coding in C? Korn shell? What?

right guys i am coding in c yes

here is the exact problem i am asking for a number 1 - 3 to be entered, and i only want them to input 1 - 3, i have validated against input of numbers outside that range and need to know how to validate against a charcater being entered, hope this helps

So you have already checked that they've entered numbers between 1 and 3?

Then what you are saying is
if (x == '1') {
do something;
}
if (x =='2' {
do s/t;
etc...

better yet...

switch (x) {
case '1':
{
do something:
}
break;
case '2':

    \{
     do something:
     \}
     break;

case '3':

    \{
     do something:
     \}
     break;
default:
    printf\("Please enter values between 1 and 3!"\);
    break;

}

Let me know if this helps or if I understand.

Gianni

not really mate, cause what i am doing is, they enter a number, which must be 1 - 3 if it is it does something, else it prints an error i can do it for outside the limits but not for charcter input.

I still don't understand what the issue is but you can look at:

isalpha(c)
islower(c)
tolower(c)
isupper(c)
toupper(c)
isdigit(c)
isalnum(c)

and maybe use a combination or one or several to get what you want...(ex, if isalpha() returns TRUE(non-zero) then use tolower(c) make make all entries lowercase then do your comparison...)

Good luck.

right then to make this super clear dude

if (vert >3)
{
prinf("too big\n");
printf("re-enter\n");
}
else if (vert <1)
{
printf("too small\n");
printf("please re-enter\n");
}
else
printf("well don correct");

but if the person enters a character the program crashes , any help at all
ian

if (!isdigit(vert))
printf("Invalid input (enter a number)");
else if (vert > 3)
printf("blah blah...");
else if (vert < 1)
printf("blah blah...");
else
{
/* do your stuff here */
}

sorry to be a pain but that dont work mate it wont let you enter any valuer in what so ever

Post the entire program. The exact method to validate input depends on how the input is obtained.