【发布时间】:2015-04-15 23:35:44
【问题描述】:
我应该使用函数和结构来创建一个程序,该程序允许用户输入密码列表和密码提示列表,其中只有一个是正确的。您应该将提示与您输入的可能密码相匹配,并从那里确定正确的密码。这是一个示例运行:
输入:
3
密码
秘密11
qwertyui
输出:
4
*******1
s*********
*e******
*******q
秘密11
这是我目前所拥有的:
#include <stdio.h>
#include <string.h>
struct Option {
char password[50];
int matches;
};
// Checks to see if the given password matches the given pattern.
// Returns false (0) if it does not, or true (1) if it does.
int is_match(char password[], char pattern[]){
}
int main(){
int N,i;
printf("Enter the N value\n");
scanf("%d", &N);
struct Option A[100];
for(i=0; i<N; i++);{
scanf("%s", &A[i].password);
}
int M;
scanf("%d", &M);
//struct Option A[100];
int j;
for(j=0; j<M; j++);{
scanf("%s", &A[i].matches);
}
return 0;
}
我的程序在第一个 scanf 处停止,只允许我输入两个密码。这一步不知道怎么调试。
【问题讨论】:
-
在没有经过严格检查的情况下查看您的程序告诉我,由于您忽略了
scanf()的返回值,因此您不能抱怨错误的结果。 -
如何不忽略返回值?对不起,我现在在我的编程课上苦苦挣扎
-
您需要检查,特别是当说明符是
"%d"->if (scanf("%d", &target) != 1) problem(); else ok();但您的问题是 @Ian 解释的分号。 -
你不需要在你的结构中的某处有一个提示字段吗?匹配字段的用途是什么?
-
我认为匹配字段是提示字段。如,加星标的单词是我们应该与我们输入的原始单词一起观看的单词
标签: c