Although if you're going to print only one char, you might as well use putchar.
Printable View
Although if you're going to print only one char, you might as well use putchar.
This program, when executed alone, works... And does what I want... ~to output asterisks as the user types in something...
..i got it from the internet by Google'ing it...Code:#include<stdio.h>
#include<conio.h>
char pw[25],ch;
int i;
int main()
{
clrscr();
puts("Enter password");
while(1)
{
if(i<0)
i=0;
ch=getch();
if(ch==13)
break; /*13 is ASCII value of ENTER*/
if(ch==8) /*ASCII value of BACKSPACE*/
{
putch('\b');
putch(NULL);
putch('\b');
--i;
continue;
}
pw[i++]=ch;
ch='*';
putch(ch);
}
pw[i]='\0';
printf("\n\n%s",pw);
getch();
return 0;
}
Now this one is the program that we're working of...
I tried to integrate the code above, but it's not working..
..can you please help me? thanks in advance.. -_+Code:#include<stdio.h>
#include<conio.h>
int main()
{
char name[20], passcode[20], option, pass_ch, spinstr[] = "|/-\\|";
int x=0;
do
{
clrscr();
printf("\n\n\tEnter your name: ");
fgets(name, sizeof(name), stdin);
printf("\n\tEnter the passcode: ");
while(1)
{
if(x<0)
{
x = 0;
pass_ch = getch();
if(pass_ch==13) break; /*ENTER*/
if(pass_ch==8); /*BACKSPACE*/
{
putch('\b');
putch(NULL);
putch('\b');
--x;
continue;
}
passcode[x++] = pass_ch;
pass_ch = '*';
putch(pass_ch);
}
}
passcode[x]='\0';
printf("\n\n\n\tPress \"Enter\" to proceed...");
clrscr();
printf("\n\n\n\tPlease wait. Analyzing data...");
while(x < 5)
{
gotoxy(42,4); printf("%c", spinstr[x]);
sleep(1);
x++;
}
clrscr();
printf("\n\n\n\tYour name is: ");
textcolor(LIGHTBLUE); cprintf("%s", name);
printf("\n\n\t");
textcolor(LIGHTGRAY); cprintf("Verifying passcode");
x=0;
while(x < 7)
{
printf(".");
sleep(1);
x++;
}
do
{
clrscr();
printf("\n\n\n\tThe passcode that you have entered is: ");
if(!strcmp(passcode, "XMod749"))
{
textcolor(LIGHTBLUE+128); cprintf("ACCEPTED.");
getch();
return 0;
}
else
{
textcolor(LIGHTRED+128); cprintf("INVALID!");
getch();
printf("\n\n\t");
textcolor(LIGHTGRAY); cprintf("What do you want to do?");
printf("\n\n\t\tExit [E] or Retry [R]? ");
option = getche();
option = toupper(option);
if(option=='E') return 0;
}
if(!(option=='E'||option=='R'))
{
printf("\n\n\tInvalid command entered. Please try again.");
getch();
}
} while(!(option=='E'||option=='R'));
} while(option=='R');
return 0;
}