It works for the first time but when it loop nothing is stored wondering whats wrong
could someone help me out please?

void main ()
{   char buffer[256] = {0};
	char password[] = "test";
	char c,i=0;
	int pos = 0;

	do
	{
	buffer[0]='\0';
	printf("%s", "Enter password: ");
	do {        
		c = getch();
	if( isprint(c) )         
	{
		flushall();
		buffer[ pos++ ] = c;
		printf("%c", '*');
	}        
	else if( c == 8 )
	{            
		buffer[ pos-- ] = '\0';
		printf("%s", "\b \b");
	}    } while( c != 13 );
	if( !strcmp(buffer, password) )
		printf("\n%s\n", "Logged on succesfully!");
	else
		printf("\n%s\n", "Incorrect login!");
	i++;
}while(i!=5);
}

is the better?
well i was taught to use flushall(); when i have problem with gets() so i tried here

int main ()

{        char buffer[ 256 ] = { 0 };
	char password[] = "test";
	char c , i = 0 ;
	int pos = 0 ;

	do
	{
	buffer[0] = '\0' ;
	printf("Enter password: ");
	do {        
		c = getch();

		if( isprint(c) )         
		{
		     buffer[ pos++ ] = c;
		     printf("%c", '*');
		} 
       
		else

		if( c == 8 )//8 is backspace
		{            
		buffer[ pos-- ] = '\0' ;
		printf("%s", "\b \b" );
		}    
		} while( c != 13 );

	if( !strcmp(buffer, password) )

		printf("\n%s\n", "Logged on succesfully!");

	else

		printf("\n%s\n", "Incorrect login!");

	i++;

	}while(i!=5);

	return 0;
	}

Edited 5 Years Ago by newprogramer: n/a

is the better?[/url]

Much!!!! :)

well i was taught to use flushall(); when i have problem with gets() so i tried here[/url]

You were taught wrong.
1) See this about gets() .
2) See this about fflush() , which is a subset of fflushall() . Neither are guaranteed to work on input streams. Only output streams.

This article has been dead for over six months. Start a new discussion instead.