Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I've compiled and executed the following c code in borland c++ compiler. It works in it perfectly but it is not working in visual c++ 6.0 compiler. What changes are to be made to make it work in visual c++ 6.0?

C++
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
 
int main()
{
    char buffer[256] = {0};
    char password[] = "password";
    char c;
    int pos = 0;
 
    printf("%s", "Enter password: ");
    do {
        c = getch();
 
		  if( isprint(c) )
        {
            buffer[ pos++ ] = c;
            printf("%c", '*');
        }
        else if( c == 8 && pos )
		  {
            buffer[ --pos ] = '\0';
            printf("%s", "\b \b");
        }
	 } while( c != 13&& pos < 256 );
 
    if( !strcmp(buffer, password) )
        printf("\n%s\n", "Logged on succesfully!");
    else
        printf("\n%s\n", "Incorrect login!");
 
    return 0;
}
Posted
Updated 30-Jan-11 8:04am
v2

What does 'it is not working in visual c++ 6.0 compiler' mean?

Does it compile but not run?
Does it compile but throw errors? If so what are the errors?
Does it not compile? If so, once again, what are the errors?
 
Share this answer
 
Comments
laragupta 30-Jan-11 14:26pm    
It compiles. but it does not take in the inputs during execution
Henry Minute 30-Jan-11 16:04pm    
As HimanshuJoshi says that indicates that you should use getchar() which is in stdio.h.
Looks like conio.h header file might be an issue here. It is not available under Visual C++ compilers along with "getch()" function. You need to use getchar().
 
Share this answer
 
Comments
laragupta 30-Jan-11 14:40pm    
ok. but what other header file should i be using if i dont use conio.h?
HimanshuJoshi 30-Jan-11 16:25pm    
stdio.h will suffice for getchar() function.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900