I need to make this work Linux, I know that conio.h is not for Linux and the main problem is getch() function. I tried using another lib like curses.h but still I got a lot of errors. It takes users input of password and converts it to **** for safety reasons.
Old code:
#include<stdio.h>
#include<conio.h>
void main()
{
char password[25],ch;
int i;
clrscr();
puts("Enter password: ");
while(1)
{
if(i<0)
i=0;
ch=getch();
if(ch==13)
break;
if(ch==8)
{
putch('b');
putch(NULL);
putch('b');
i--;
continue;
}
password[i++]=ch;
ch='*';
putch(ch);
}
password[i]='';
printf("\nPassword enterd : %s",password);
getch();
}
Updated code based on @SouravGhosh's answer:
#include<stdio.h>
int main(void)
{
char password[25],ch;
int i;
//system("clear");
puts("Enter password: ");
while(1)
{
if(i<0)
i=0;
ch=getchar();
if(ch==13)
break;
if(ch==8)
{
putchar('b');
putchar('b');
i--;
continue;
}
password[i++]=ch;
ch='*';
putchar(ch);
}
password[i]=' ';
printf("\nPassword enterd : %s",password);
getchar();
return 0;
}