如何解决C 不读取第二个 getch()
我的 C 程序不允许我读取第二个 getch() 值。有谁知道这是怎么回事??
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
struct user{
char username[30],password[30],confirmpass[30];
};
int main(){
struct user u[10];
int i,j,n;
printf("Enter the number of users: ");
scanf("%d",&n);
for(int i=0;i<n;i++){
printf("Enter the username: ");
scanf("%s",&u[i].username);
printf("Enter the password that comprises of alphabets and numerics only and should be 8 characters long: ");
for(int j=0;i<8;i++){
u[i].password[j]=getch();
printf("*");
}
printf("Confirm the password: ");
for(int j=0;i<8;i++){
u[i].confirmpass[j]=getch();
printf("*");
}
for(int i=0;i<strlen(u[i].password);i++){
if(strcmp(u[i].password,u[i].confirmpass)==0){
printf("The passwords don't match");
exit(0);
}
}
printf("The user details have been successfully registered!!");
exit(0);
}
}
我在这里使用了 getch() 来屏蔽密码。我在使用gets() 时也遇到了类似的逻辑错误。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。