cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/12/17:46:49

Message-ID: <001101bd7ded$f8a31380$a74e08c3@arthur>
From: "Arthur" <arfa AT clara DOT net>
To: "DJGPP Mailing List" <djgpp AT delorie DOT com>
Subject: Why doesn't this work?
Date: Tue, 12 May 1998 22:33:57 +0100
MIME-Version: 1.0

This is a multi-part message in MIME format.

------=_NextPart_000_0006_01BD7DF6.0DB2F260
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Found a simple password program in QBASIC and as an exercise tried to
convert it to C. So simple, you may say. It is, but for the life of me I
could not get printf (of all things) to work.

Source attached.

Yes, I know that it is not optimised fully, but the routine is there and I
know it works. Why does it not prompt you for your password until after you
have typed it?

It works if I use cprintf or scanf, so I assume that after printf is used,
the text is not printed until some interrupt is set off (like a function
call). I thought it was the simple "print to stdout" routine?

James Arthur
jaa AT arfa DOT clara DOT net



------=_NextPart_000_0006_01BD7DF6.0DB2F260
Content-Type: application/octet-stream;
	name="password.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="password.c"

#include <stdio.h>
#include <pc.h>
#include <conio.h>
#include <string.h>


char password(void)
{
	char letter[5],count;
	
	printf("\n\n Please enter your password:  ");
	
	for (count=0;count<5;count++)
	{
		while (kbhit()!=0);
		
		letter[count]=getch();
		printf("*");
		
	}
	
	letter[5]='\0';
	
	return (!strcmp(letter,"hello"));
}


int main(void)
{
	printf("-------------------------\n");
	printf("-- PASSWORD PROTECTION --\n");
	printf("-------------------------\n");
	
	while(password()==0);

	printf("\n\n  Password Accepted!");
	
	return 0;
}

------=_NextPart_000_0006_01BD7DF6.0DB2F260--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019