【发布时间】:2021-09-08 13:23:41
【问题描述】:
#include <stdio.h>
#include <conio.h>
#define max 100
void compare(char *name,char* input);
int main()
{
int i=0;
char name[max]="santosh";
char input[max];
printf("enter the password\n");
while((input[i]=getchar())!='\n'){
i++;
}
input[i]='\0';
compare(name,input);
return 0;
}
void compare(char *name,char* input){
while((*name==*input)&&(*name!='\0'&&*input != '\0')){
*name++;
*input++;
}
if(*name=='\0'&&*input=='\0')
printf("Correct Password");
else
printf("Incorrect Password");
}
这个程序在 vs 代码中崩溃了,但是当我使用 getchar() 而不是 getch() 或 getche() 时一切正常。 为什么它不能与 getch() 一起使用,以及它将如何运行,因为我希望用户插入密码并因此想要使用 getch() 而不是 getchar()。
【问题讨论】:
-
您的用户不会在 VSCode 中运行。这就是区别。在真正的 cmd 控制台中运行它,它应该可以与 getch 一起使用。
标签: arrays c string while-loop getch