Created
September 21, 2016 11:17
-
-
Save devils-ey3/2e3fa731f01849df1b509dd52f4f8a0f to your computer and use it in GitHub Desktop.
String filter or password filter in c. In this code it will filter every single input so your code isn't crush by this filter code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include "conio.h" | |
int password(); | |
int pass_system(); | |
int main () | |
{ | |
if (!password()) | |
{ | |
printf("The game is terminated"); | |
return 0; | |
} | |
else | |
printf("You can play"); | |
} | |
char ch,ch1[80];int i; // global variable | |
int password () ///for password matching | |
{ | |
char pass[80]="open it"; | |
int increment=3; | |
printf("Enter the password : "); | |
pass_system(); | |
while (strcmp(pass,ch1) && increment>0) | |
{ | |
// if (strcmp(pass,ch1)==0) | |
// break; | |
if (increment==1) | |
{ | |
printf("Sorry ^_^ .. Next time please\n"); | |
return 0; | |
} | |
system("clear"); | |
printf("You have %d chance left \n",increment-1); | |
--increment; | |
printf("Enter password : "); | |
pass_system(); | |
} | |
return 1; | |
} | |
int pass_system() /// for password input | |
{ | |
i=0; | |
while ( (ch=getch()) !='\n' && i <79) ///scan single character but not displayed in console | |
{ | |
printf("*"); | |
ch1[i++]=ch; ///put the character into | |
} | |
ch1[i]='\0'; | |
printf("\n"); | |
return ch1[i]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment