Challenge #1

+1 c student · December 27, 2014
#include <stdio.h>
#include <ctype.h>

#define SIZE 8

typedef enum {
    FALSE,
    TRUE,
} boolean;

int main (void) {
    
    boolean b[4] = {FALSE};
    int c;
    int n;
    
    printf ("Enter a string with:\n"
        "\ta minimum of length: %d,\n"
        "\tan uppercase letter,\n"
        "\ta number,\n"
        "\tand a special character\n", SIZE);
        
    for (n = 0; c != '\n'; n++) {
        c = getchar();
        b[0] |= isupper (c) ? TRUE : FALSE;
        b[1] |= isdigit (c) ? TRUE : FALSE;
        b[2] |= ispunct (c) ? TRUE : FALSE;
    }
    
    b[3] = n >= SIZE ? TRUE : FALSE;
    (b[0] && b[1] && b[2] && b[3]) ? puts ("Valid\n") :
                                     puts ("Invalid\n");

    return 0;
}

?

Post a Reply

Replies

Oldest  Newest  Rating
0 c student · December 28, 2014
it was meant to be small and compact but yes, its readability is absolutely terrible.  as for the content, you learn these things by yourself.  you probably won't find this in any video online.
0 Alex Berezovsky · December 28, 2014
where did you learn all of this? he never went over it in any video
0 Nishant Tadvi · December 28, 2014
Its nice but something i can't understand anyway its nice.
  • 1

C

126,610 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator