Friday, October 7, 2022
HomeC ProgrammingC program to examine lowercase or uppercase utilizing macro

C program to examine lowercase or uppercase utilizing macro


Write a C program to examine whether or not a personality is uppercase or lowercase utilizing macro. Logic to examine uppercase or lowercase character utilizing macro in C. How one can examine whether or not a personality is uppercase or lowercase utilizing macro in C program.

Throughout the course of this macro workouts, in final submit 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 submit we’ll proceed additional with string operation. I’ll clarify how simply you possibly can rework logic to examine uppercase and lowercase character to macro.

Required information

Primary C programming, Macros, Conditional operator, String

How one can examine uppercase and lowercase character utilizing macro?

Earlier than shifting forward, I assume that you’re conscious with macro syntax, how you can 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 examine uppercase and lowercase utilizing macro

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

#embrace <stdio.h>

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

int important()
{
    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 shouldn't be alphabet");

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

You possibly can lengthen the logic additional to examine alphabets, digits, alphanumeric, vowels, consonants, particular characters and so forth. Beneath is the record of macro definitions to examine 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))

Glad coding 😉

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments