简体   繁体   English

在命令提示符下无输出

[英]No output in command prompt

My program, which is for generating an acceptable password, is not displaying any output aside from input prompt and it lets me input the password but the program immediately ends. 我的程序用于生成可接受的密码,除了输入提示外,没有显示任何输出,它可以让我输入密码,但程序立即结束。 I get no errors on my end or warnings on my debugger. 我没有收到任何错误,也没有收到调试器的警告。 Was wondering if someone could give me some input. 想知道是否有人可以给我一些意见。

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

You are not getting an output because strnlen(password, 15) is between 2 and 15 , use an else part: 您没有得到输出,因为strnlen(password, 15)215之间,请使用else部分:

if (a < 2 || a > 15) {
   ...
} else {
   /* your output here */
}

On the other hand: 另一方面:

if (isdigit(strnlen(password, 15)) == false) {

is a nonsense, isdigit checks if a character is a decimal digit, but you are passing a size_t instead of a char , same for isalpha . 是一个废话, isdigit检查字符是否为十进制数字,但是您要传递一个size_t而不是char ,与isalpha相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM