开发者

what code to use when using visual c++ 6.0

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 ?

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


vc 6, does not support conio. Remove the include.

getch will not do what you expect it to do.

Look into building a console app under vc6.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜