C 命令提示符中没有输出
我的程序是用来生成一个可接受的密码的,除了输入提示之外,它没有显示任何输出,它允许我输入密码,但程序立即结束。我在调试器上没有收到任何错误或警告。我想知道是否有人能给我一些建议C 命令提示符中没有输出,c,arrays,string,function,pointers,C,Arrays,String,Function,Pointers,我的程序是用来生成一个可接受的密码的,除了输入提示之外,它没有显示任何输出,它允许我输入密码,但程序立即结束。我在调试器上没有收到任何错误或警告。我想知道是否有人能给我一些建议 #include "stdafx.h" #include <stdio.h> #include <ctype.h> #include <string.h> int main() { char password[15] = {'\0'}; char search[15
#include "stdafx.h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main()
{
char password[15] = {'\0'};
char search[15] = { '\0' };
int a, b, c, d, e;
char punct[] = { '!','@','#','$','%','^','&','*','?','_', '\0' };
printf("Enter your test password: \n");
fgets(password, 15, stdin );
a = strnlen(password, 15);//judges length of search between the numbers 2 and 15
b = strncmp(password, punct, 10);
c = isalpha(strnlen(password,15));
d = isdigit(strnlen(password, 15));
e = a + b + c + d;
if (a < 2 || a>15) {
printf("Must have exactly 2-15 characters.\n");
if (strncmp(password, punct, 10) == false) {//must have one of the characters included in password
printf("Must have character punctutation\n");
}
if (isdigit(strnlen(password, 15)) == false) {
printf("Must consist of at least one number 0-9.\n");
}
if (isalpha(strnlen(password, 15)) == false) {
printf("Must consist of at least one letter a-z\n");
}
else {
printf("You have inputted a legal password!\n");
}
}
return 0;
}
#包括“stdafx.h”
#包括
#包括
#包括
int main()
{
字符密码[15]={'\0'};
字符搜索[15]={'\0'};
INTA、b、c、d、e;
字符点[]={'!','@','#','$','%','^','&','*','?','#','\0'};
printf(“输入您的测试密码:\n”);
fgets(密码,15,标准输入);
a=strnlen(密码,15);//判断数字2和15之间的搜索长度
b=strncmp(密码,点,10);
c=isalpha(strnlen(密码,15));
d=isdigit(标准密码,15));
e=a+b+c+d;
如果(a<2 | a>15){
printf(“必须正好有2-15个字符。\n”);
if(strncmp(password,punct,10)=false){//必须包含密码中的一个字符
printf(“必须有字符点蚀\n”);
}
if(isdigit(strnlen(密码,15))==false){
printf(“必须至少包含一个数字0-9。\n”);
}
if(isalpha(strnlen(密码,15))==false){
printf(“必须至少包含一个字母a-z\n”);
}
否则{
printf(“您输入了合法密码!\n”);
}
}
返回0;
}
由于strnlen(密码,15)
介于2
和15
之间,因此无法获得输出,请使用其他部分:
if (a < 2 || a > 15) {
...
} else {
/* your output here */
}
if(a<2|a>15){
...
}否则{
/*你的输出在这里*/
}
另一方面:
if(isdigit(strnlen(密码,15))==false){
这是胡说八道,isdigit
检查字符是否是十进制数字,但您传递的是size\u t
而不是char
,这与isalpha
相同您的输入长度>=2或者为什么要对长度执行isalpha?和isdigit?(无关)我想如果它运行带有isalpha或digit的数组,它会给我一个int,我可以用它来表示一个真的假语句isalpha和isdigit测试一个字符,而不是一个字符串,搜索每个字符以获得它们的正确用法char password[15]
-->char password[15+2]
asfgets()
需要空间来放置'\n'
和'\0'
。使用fgets(密码,passowrd的大小,stdin);
并在fgets()
之后去掉尾随的。
是否有一个命令或循环可以让我扫描输入的字符。我只是认为isdigit会返回一个0(false)这可能会转化为将它与一个真假陈述进行比较。这没有帮助,而且我现在可能比以前更困惑了