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);
}

Start by formatting your code properly. You are probably getting lost, as I am, trying to decipher your code.

What us the flushall() supposed to be doing?

See this also.

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;
	}

Line 39:

for(int j=0;j<=pos;j++)
  buffer[j] = '\0';

Line 39 and 1/2: ;)

pos = 0;

thanks very much it works

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.