![]() |
| | #1 |
| Registered User Join Date: Nov 2009
Posts: 12
| Code: #include <stdio.h>
#include <string.h>
main()
{
char pass1[20];
char pass2[]= "password";
int i=0;
do
{
i++;
clrscr();
printf("Enter Password: ");
gets(pass1);
if(strcmp(pass1,pass2)==0)
printf("Congrats!");
else
printf("Invalid Password %i Tries\n");
}
while((strcmp(pass1,pass2)!=0 || i!=3);
getche();
}
|
| jappy512 is offline | |
| | #2 |
| Registered User Join Date: Nov 2009
Posts: 51
| I'm only starting out myself but you may get more suggestions if you say what the error is you are experiencing |
| Martin_T is offline | |
| | #3 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,643
| You probably want && instead of ||. Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? |
| quzah is offline | |
| | #4 |
| DESTINY Join Date: Jul 2008 Location: in front of my computer
Posts: 803
| Code: #include <stdio.h>
#include <string.h>
main()
{
char pass1[20];
char pass2[]= "password";
int i=0;
do
{
i++;
clrscr();
printf("Enter Password: ");
gets(pass1); //use fgets instead
if(strcmp(pass1,pass2)==0)
printf("Congrats!");
else
printf("Invalid Password %i Tries\n");
}
while((strcmp(pass1,pass2))!=0 && i!=3);
getche();
}
__________________ HOPE YOU UNDERSTAND....... By associating with wise people you will become wise yourself It's fine to celebrate success but it is more important to heed the lessons of failure We've got to put a lot of money into changing behavior PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D. IDE- Microsoft Visual Studio 2008 Express Edition |
| BEN10 is offline | |
| | #5 |
| Registered User Join Date: Jan 2009
Posts: 224
| Code: printf("Invalid Password %d Tries\n", i);
Last edited by Subsonics; 11-22-2009 at 10:48 AM. |
| Subsonics is offline | |
| | #6 |
| Registered User Join Date: Nov 2009
Posts: 12
| Thanks for the immediate response guys... Tried removing the clrscr() and it shows in the execution of the program 1277 tries... Why it exceeds the condition i!=3? Thanks in advance.... |
| jappy512 is offline | |
| | #7 |
| Registered User Join Date: Nov 2009
Posts: 12
| I tried it again and the code works now... My question now is how do we clear the screen after the first trial are made? example: Enter Password: dasdadad //entered incorrect password Invalid Password 1 Tries //Then Clears the screen after showing the number of tries Enter Password: //This will show up only 3 times until the correct password or 3 trials are met. Thanks guys... ^_^ |
| jappy512 is offline | |
| | #8 | |
| Registered User Join Date: Sep 2006
Posts: 3,156
| Quote:
The real problem, of course, is that anyone looking, can see what the user is keyboarding in as their password. The only two ways I know to solve that, are: 1) Include the windows.h header and use the Windows API, and SetConsoleMode() to set the monitor to no echo mode, while the password is being entered (and you can use SetConsoleCursorPosition() also, as you want to). 2) go back to using the DOS style console cursor control and control of the keyboard input to the terminal - getch() gets a key with no echo to the monitor, and gotoxy() will set the cursor to any place on the console window. It would be good if the password was encrypted on a file, also. ![]() There are other ways to do this, but they involve a little bit of another language, not C. Note that while #2 is included, it is not using standard C, and wouldn't be portable with newer compilers. Last edited by Adak; 11-23-2009 at 02:51 AM. | |
| Adak is offline | |
| | #9 |
| Registered User Join Date: Nov 2009
Posts: 12
| Thanks to all the reply guys.... It helped me a lot and now the program runs smoothly because of all your suggestions.. Thank You Very Much.. ^_^ |
| jappy512 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem in multi times table | lolguy | C Programming | 11 | 12-28-2008 11:17 AM |
| Problem reading a password from a file. | medeshago | C Programming | 15 | 12-21-2008 07:20 AM |
| problem: online on winxp and linux red hat | gemini_shooter | Linux Programming | 5 | 05-29-2005 02:14 PM |
| Problem reading from external file | djayz | C Programming | 13 | 03-24-2005 01:15 PM |
| i have problem with my code... | jayton | C Programming | 5 | 02-15-2005 03:10 PM |