password program needed help. I have the code here. Thank you.

hello guys. i just would like to know if my program is correct according to the instruction below. If someone could answer this right away, please do reply me. My e-mail add is borinah_8@yahoo.com or just reply to this forum. I'm gonna pass this assignment tomorrow. Thank you and more power.God bles you all.By the way, i'm using turbo c.

Password Program

Create a program that will ask the user for a password. The password string will be concealed by showing only the character asterisk ('*'). There are only three tries and, after which the user still fails to determine the password, the program terminates. The program also terminates if the user pressed ESC key. Let the password be 10 characters long. In order to compare two strings, use the following function in STRING.H

strcmp(str1,str2);
where: str1 is the target string.
str2 is the source string.

This function returns the following values:
0 = when both strings are the same.
non-zero = when both strings are different.

here's my program:

#include
#include
#include

#define PASS_sarangsurowo 13

int main(){
char name;
char pass[PASS_sarangsurowo+1];
int i=0;

memset (pass,0,PASS_sarangsurowo+1);
clrscr();
printf("Login username: ");
scanf("%c", &name);
printf("Password: ");
for(i=0;i<PASS_sarangsurowo;i++){
char c=getch();

if(c=='
'||c==PASS_sarangsurowo)
break;
pass[i]=c;
putch('*');
}
if(!strcmp(pass,"Password"))
printf("
WELCOME!");

else
printf("");
getch();
return 0;
}


Comments

  • : hello guys. i just would like to know if my program is correct
    : according to the instruction below. If someone could answer this
    : right away, please do reply me. My e-mail add is borinah_8@yahoo.com
    : or just reply to this forum. I'm gonna pass this assignment
    : tomorrow. Thank you and more power.God bles you all.By the way, i'm
    : using turbo c.
    :
    : Password Program
    :
    : Create a program that will ask the user for a password. The password
    : string will be concealed by showing only the character asterisk
    : ('*'). There are only three tries and, after which the user still
    : fails to determine the password, the program terminates. The program
    : also terminates if the user pressed ESC key. Let the password be 10
    : characters long. In order to compare two strings, use the following
    : function in STRING.H
    :
    : strcmp(str1,str2);
    : where: str1 is the target string.
    : str2 is the source string.
    :
    : This function returns the following values:
    : 0 = when both strings are the same.
    : non-zero = when both strings are different.
    :
    : here's my program:
    :
    : #include
    : #include
    : #include
    :
    : #define PASS_sarangsurowo 13
    :
    : int main(){
    : char name;
    : char pass[PASS_sarangsurowo+1];
    : int i=0;
    :
    : memset (pass,0,PASS_sarangsurowo+1);
    : clrscr();
    : printf("Login username: ");
    : scanf("%c", &name);
    : printf("Password: ");
    : for(i=0;i<PASS_sarangsurowo;i++){
    : char c=getch();
    :
    : if(c=='
    '||c==PASS_sarangsurowo)
    : break;
    : pass[i]=c;
    : putch('*');
    : }
    : if(!strcmp(pass,"Password"))
    : printf("
    WELCOME!");
    :
    : else
    : printf("");
    : getch();
    : return 0;
    : }
    :
    :
    :
    It looks ok, except that you don't ask the user for 3 tries but only once.
  • : : hello guys. i just would like to know if my program is correct
    : : according to the instruction below. If someone could answer this
    : : right away, please do reply me. My e-mail add is borinah_8@yahoo.com
    : : or just reply to this forum. I'm gonna pass this assignment
    : : tomorrow. Thank you and more power.God bles you all.By the way, i'm
    : : using turbo c.
    : :
    : : Password Program
    : :
    : : Create a program that will ask the user for a password. The password
    : : string will be concealed by showing only the character asterisk
    : : ('*'). There are only three tries and, after which the user still
    : : fails to determine the password, the program terminates. The program
    : : also terminates if the user pressed ESC key. Let the password be 10
    : : characters long. In order to compare two strings, use the following
    : : function in STRING.H
    : :
    : : strcmp(str1,str2);
    : : where: str1 is the target string.
    : : str2 is the source string.
    : :
    : : This function returns the following values:
    : : 0 = when both strings are the same.
    : : non-zero = when both strings are different.
    : :
    : : here's my program:
    : :
    : : #include
    : : #include
    : : #include
    : :
    : : #define PASS_sarangsurowo 13
    : :
    : : int main(){
    : : char name;
    : : char pass[PASS_sarangsurowo+1];
    : : int i=0;
    : :
    : : memset (pass,0,PASS_sarangsurowo+1);
    : : clrscr();
    : : printf("Login username: ");
    : : scanf("%c", &name);
    : : printf("Password: ");
    : : for(i=0;i<PASS_sarangsurowo;i++){
    : : char c=getch();
    : :
    : : if(c=='
    '||c==PASS_sarangsurowo)
    : : break;
    : : pass[i]=c;
    : : putch('*');
    : : }
    : : if(!strcmp(pass,"Password"))
    : : printf("
    WELCOME!");
    : :
    : : else
    : : printf("");
    : : getch();
    : : return 0;
    : : }
    : :
    : :
    : It looks ok, except that you don't ask the user for 3 tries but only
    : once.

    Thank you for the reply. May I just ask, how to ask the user to do it 3 times?? Thank you.

  • : : hello guys. i just would like to know if my program is correct
    : : according to the instruction below. If someone could answer this
    : : right away, please do reply me. My e-mail add is borinah_8@yahoo.com
    : : or just reply to this forum. I'm gonna pass this assignment
    : : tomorrow. Thank you and more power.God bles you all.By the way, i'm
    : : using turbo c.
    : :
    : : Password Program
    : :
    : : Create a program that will ask the user for a password. The password
    : : string will be concealed by showing only the character asterisk
    : : ('*'). There are only three tries and, after which the user still
    : : fails to determine the password, the program terminates. The program
    : : also terminates if the user pressed ESC key. Let the password be 10
    : : characters long. In order to compare two strings, use the following
    : : function in STRING.H
    : :
    : : strcmp(str1,str2);
    : : where: str1 is the target string.
    : : str2 is the source string.
    : :
    : : This function returns the following values:
    : : 0 = when both strings are the same.
    : : non-zero = when both strings are different.
    : :
    : : here's my program:
    : :
    : : #include
    : : #include
    : : #include
    : :
    : : #define PASS_sarangsurowo 13
    : :
    : : int main(){
    : : char name;
    : : char pass[PASS_sarangsurowo+1];
    : : int i=0;
    : :
    : : memset (pass,0,PASS_sarangsurowo+1);
    : : clrscr();
    : : printf("Login username: ");
    : : scanf("%c", &name);
    : : printf("Password: ");
    : : for(i=0;i<PASS_sarangsurowo;i++){
    : : char c=getch();
    : :
    : : if(c=='
    '||c==PASS_sarangsurowo)
    : : break;
    : : pass[i]=c;
    : : putch('*');
    : : }
    : : if(!strcmp(pass,"Password"))
    : : printf("
    WELCOME!");
    : :
    : : else
    : : printf("");
    : : getch();
    : : return 0;
    : : }
    : :
    : :
    : :
    : It looks ok, except that you don't ask the user for 3 tries but only
    : once.

    How can I let the user to do it 3 tries???
    please help me. I need to pass this assignment tomorrow. Thanks in advance.

  • : How can I let the user to do it 3 tries???

    Put it inside a loop. I can show you a way if you are unable to get it working.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories