Tuesday, August 16, 2011

Saving Password in a file

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
char pw[100];
char *ptr;
int i=0;
FILE *fp;
clrscr();
printf("Enter the password:\n");
ch=getch();
while(ch!=13)
{
if(ch==8)
{
printf("\b");
putch(NULL);
printf("\b");
pw[i]='\0';
--i;
}
else
{
printf("%c",ch);
putch('\b');
printf("*");
pw[i++]=ch;
}
ch=getch();
}
pw[i]='\0';
ptr=pw;
fp=fopen("c:\milan.txt","w");
while(*ptr!='\0')
{
fputc(*ptr,fp);
ptr++;
}
printf("\nPassword successfully saved in the file");
getch();
}

No comments:

Post a Comment

Feel free to comment......