Connecting Tech Pros Worldwide Help | Site Map

how to check whether input from user minimum/maksimum example for password

ija ija is offline
Newbie
 
Join Date: Oct 2006
Posts: 4
#1: Oct 13 '06
i try to limit the user key in integer at least 1 and not more than 8. pls help me..
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,162
#2: Oct 13 '06

re: how to check whether input from user minimum/maksimum example for password


Put your input statement in a loop, when they have given an input check it's value and if it is wrong print an error message and ask for another input.
Newbie
 
Join Date: Sep 2006
Posts: 22
#3: Oct 13 '06

re: how to check whether input from user minimum/maksimum example for password


Quote:

Originally Posted by ija

i try to limit the user key in integer at least 1 and not more than 8. pls help me..


Hi Check the code below, You will get some idea

void getpass(char passwd[])
{
int ch;
while(1)
{
printf("Enter your password : ");
u_int index=0;
while((ch=getch())!=13)
{
if(index < 8)
{
passwd[index]=ch;
}
index++;
putch('*');
}
if(index <2 || index > 8)//enter key
{
printf("\nPassword should be more than 1 and less than 9 charactes");
printf("\nPress any key to enter again...");
while(!_kbhit());
system("cls");
getch();
continue;
}
else
{
passwd[index]='\0';
break;
}
}
}
int main(int argc,char* argv[])
{
char passwd[9];
getpass(passwd);
printf("\npassword : %s\n",passwd);
return 0;
}
ija ija is offline
Newbie
 
Join Date: Oct 2006
Posts: 4
#4: Oct 13 '06

re: how to check whether input from user minimum/maksimum example for password


Quote:

Originally Posted by zahidkhan

Hi Check the code below, You will get some idea
}

yep.. yr code looks complicated.. not really understand.. can u check this example? how the array length is not 6 as i declared?

#include <stdio.h>
#include <string.h>
main ()
{
char a[8];
int size;

clrscr();
printf("Input1 : ");
scanf("%s",&a);
length = strlen(a);
printf("\nlength this input is = %d",length);

if (length <=8)
{ ... proceed instruction here}
else
{ print error}

getch();
}
ija ija is offline
Newbie
 
Join Date: Oct 2006
Posts: 4
#5: Oct 13 '06

re: how to check whether input from user minimum/maksimum example for password


i try the strlen just now... the program ok, no problem but new prob appear.
i have prob with this short prog (eample), output doesn't capture any Y or N char.... why ? and how to correct it?

char answer;
do
{ //some instruction goes here

printf("Are u sure to checkout ?Y/N ");
scanf("%c",&answer);
}
while((answer != 'N') || (answer != 'n');
Reply