Skip to content

Instantly share code, notes, and snippets.

@Mashpy
Created July 5, 2016 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mashpy/08d9bb1acfe7ebd3787078be109cba48 to your computer and use it in GitHub Desktop.
Save Mashpy/08d9bb1acfe7ebd3787078be109cba48 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
int main()
{
int ch;
char pword[BUFSIZ];
int i = 0;
puts ("Enter your password");
fflush(stdout);
while ((ch = getch()) != EOF
&& ch != '\n'
&& ch != '\r'
&& i < sizeof(pword) - 1)
{
if (ch == '\b' && i > 0)
{
printf("\b \b");
fflush(stdout);
i--;
pword[i] = '\0';
}
else if (isalnum(ch))
{
putchar('*');
pword[i++] = (char)ch;
}
}
pword[i] = '\0';
printf ("\nYou entered >%s<", pword);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment