Thread: masked with asterisk(*)?

  1. #31
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Although if you're going to print only one char, you might as well use putchar.

  2. #32
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by ShadeS_07 View Post
    awww, c'mon... I wouldn't post this if I have had already think of this really hard in the first place.. I just can't figure it out.. plus, my knowledge regarding C programming is limited, so I don't even have a clue... -_+
    It's called making a flowchart and then translating it into code. It's really, really helpful for newbie programmers. Try it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #33
    Registered User
    Join Date
    Jul 2008
    Posts
    44

    Cool almost done... -_+

    This program, when executed alone, works... And does what I want... ~to output asterisks as the user types in something...

    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;
    }
    ..i got it from the internet by Google'ing it...


    Now this one is the program that we're working of...
    I tried to integrate the code above, but it's not working..

    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;
    }
    ..can you please help me? thanks in advance.. -_+

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c masked password?
    By ShadeS_07 in forum C Programming
    Replies: 2
    Last Post: 10-09-2008, 10:04 AM
  2. Masked Avatar
    By Travis Dane in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 02-05-2003, 11:54 AM
  3. can the word enter in dos be masked?
    By Jasonymk in forum C++ Programming
    Replies: 2
    Last Post: 01-20-2003, 07:47 AM