Thursday, April 25, 2024
HomeC ProgrammingC program to test lowercase or uppercase utilizing macro

C program to test lowercase or uppercase utilizing macro


Write a C program to test whether or not a personality is uppercase or lowercase utilizing macro. Logic to test uppercase or lowercase character utilizing macro in C. Tips on how to test whether or not a personality is uppercase or lowercase utilizing macro in C program.

Throughout the course of this macro workout routines, in final publish we mentioned how simply we will add situations to our macro. We discovered to discover most or minimal between two numbers utilizing macro.

On this publish we are going to proceed additional with string operation. I’ll clarify how simply you’ll be able to remodel logic to test uppercase and lowercase character to macro.

Required data

Fundamental C programming, Macros, Conditional operator, String

Tips on how to test uppercase and lowercase character utilizing macro?

Earlier than transferring forward, I assume that you’re conscious with macro syntax, tips on how to outline and use

Lets outline two macro that accepts an arguments say IS_UPPER(x) and IS_LOWER(x). Each the macro ought to return boolean true (1) or false (0) primarily based on their traits.

Instance:

#outline IS_UPPER(x) (x >= 'A' && x <= 'Z')
#outline LOWER(x) (x >= 'a' && x <= 'z')

Program to test uppercase and lowercase utilizing macro

/**
 * C program to test uppercase and lowercase utilizing macro
 */

#embody <stdio.h>

// Macro definitions
#outline IS_UPPER(x) (x >= 'A' && x <= 'Z')
#outline IS_LOWER(x) (x >= 'a' && x <= 'z')

int predominant()
{
    char ch;

    // Enter a personality from person
    printf("Enter any character: ");
    ch = getchar();

    if (IS_UPPER(ch))
        printf("'%c' is uppercasen", ch);
    else if (IS_LOWER(ch))
        printf("'%c' is lowercasen", ch);
    else 
        printf("Entered character just isn't alphabet");

    return 0;
}
Enter any character: C
'C' is uppercase

You may prolong the logic additional to test alphabets, digits, alphanumeric, vowels, consonants, particular characters and many others. Under is the checklist of macro definitions to test all.

#outline IS_UPPER(x) (x >= 'A' && x <= 'Z')
#outline IS_LOWER(x) (x >= 'a' && x <= 'z')
#outline IS_ALPHABET(x) (IS_LOWER(x) || IS_UPPER(x))

#outline IS_VOWEL_LOWER(x) (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u')
#outline IS_VOWEL_UPPER(x) (x == 'A' || x == 'E' || x == 'I' || x == 'O' || x == 'U')
#outline IS_VOWEL(x) (IS_VOWEL_LOWER(x) || IS_VOWEL_UPPER(x))

#outline IS_DIGIT(x) (x >= '0' && x <= '9')
#outline IS_ALPHANUMERIC(x) (IS_ALPHABET(x) || IS_DIGIT(x))

#outline IS_WHITE_SPACE(x) (x == ' ' || x == 't' || x == 'r' || x == 'n' || x == '')

#outline IS_SPECIAL_CHARACTERS(x) (x >= 32 && x <= 127 && !IS_ALPHABET(x) && !IS_DIGIT(x) && !IS_WHITE_SPACE(x))

Completely happy coding 😉

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments