Skip to main content
Login Register
Code2night
  • Home
  • Blog Archive
  • Learn
    • Tutorials
    • Videos
  • Interview Q&A
  • Languages
    • Angular Angular js ASP.NET Asp.net Core ASP.NET Core, C# ASP.NET MVC ASP.NET Web Forms C C# C#, ASP.NET Core, Dapper
      C#, ASP.NET Core, Dapper, Entity Framework DotNet General Web Development HTML, CSS HTML/CSS Java JavaScript JavaScript, HTML, CSS JavaScript, Node.js Node.js
      Python Python 3.11, Pandas, SQL Python 3.11, SQL Python 3.11, SQLAlchemy Python 3.11, SQLAlchemy, SQL Python 3.11, SQLite React Security SQL Server TypeScript
  • Post Blog
  • Tools
    • Beautifiers
      JSON Beautifier HTML Beautifier XML Beautifier CSS Beautifier JS Beautifier SQL Formatter
      Dev Utilities
      JWT Decoder Regex Tester Diff Checker Cron Explainer String Escape Hash Generator Password Generator
      Converters
      Base64 Encode/Decode URL Encoder/Decoder JSON to CSV CSV to JSON JSON to TypeScript Markdown to HTML Number Base Converter Timestamp Converter Case Converter
      Generators
      UUID / GUID Generator Lorem Ipsum QR Code Generator Meta Tag Generator
      Image Tools
      Image Converter Image Resizer Image Compressor Image to Base64 PNG to ICO Background Remover Color Picker
      Text & Content
      Word Counter PDF Editor
      SEO & Web
      SEO Analyzer URL Checker World Clock
  1. Home
  2. Blog
  3. C
  4. Check if the character is a vowel or a consonant.

Check if the character is a vowel or a consonant.

Date- Dec 09,2023 Updated Mar 2026 3521
c programming vowel consonant check

Understanding Vowels and Consonants

In the English alphabet, characters are categorized into two primary groups: vowels and consonants. Vowels include the letters a, e, i, o, and u, while all other alphabetic characters are considered consonants. This distinction is crucial for various applications, including language processing, speech recognition, and educational software.

When developing a program to identify whether a character is a vowel or a consonant, it is essential to consider both uppercase and lowercase letters. This ensures that the program is user-friendly and can handle input from diverse sources.

Prerequisites

Before diving into the code, ensure you have a basic understanding of the C programming language, including:

  • Data types and variables
  • Control structures such as if statements
  • Input and output functions

Familiarity with compiling and running C programs on your chosen development environment (such as GCC or an IDE like Code::Blocks) is also recommended.

Basic Program Example

Here is a simple program that checks if a character is a vowel or a consonant:

#include 

int main() {
    char ch;
    printf("Enter a character: ");
    scanf("%c", &ch);

    // Check if the character is an alphabet
    if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
        // Convert to lowercase for easier checking
        char lower = (ch >= 'A' && ch <= 'Z') ? ch + 32 : ch;

        if (lower == 'a' || lower == 'e' || lower == 'i' || lower == 'o' || lower == 'u') {
            printf("%c is a vowel.\n", ch);
        } else {
            printf("%c is a consonant.\n", ch);
        }
    } else {
        printf("%c is not an alphabet character.\n", ch);
    }

    return 0;
}
Check if the character is a vowel or a consonant

Explanation of the Code

This program begins by prompting the user to enter a character. It then checks if the character is an alphabet letter. If it is, the program converts it to lowercase to simplify the comparison against the vowels. The program uses an if-else structure to determine whether the character is a vowel or a consonant.

The use of ASCII values for checking the range of characters is essential. The ASCII values for lowercase letters 'a' to 'z' are 97 to 122, and for uppercase letters 'A' to 'Z', they are 65 to 90. This understanding helps in implementing more complex logic if needed.

Extended Functionality: Handling Special Cases

In addition to checking alphabetic characters, it may be useful to extend the functionality of our program to handle special cases, such as:

  • Checking for non-alphabetic characters (e.g., numbers, symbols)
  • Handling accented characters or letters from other alphabets
  • Allowing for user-defined vowels

Here’s an example of how to modify the program to include a check for digits and special characters:

#include 

int main() {
    char ch;
    printf("Enter a character: ");
    scanf("%c", &ch);

    if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
        char lower = (ch >= 'A' && ch <= 'Z') ? ch + 32 : ch;
        if (lower == 'a' || lower == 'e' || lower == 'i' || lower == 'o' || lower == 'u') {
            printf("%c is a vowel.\n", ch);
        } else {
            printf("%c is a consonant.\n", ch);
        }
    } else if (ch >= '0' && ch <= '9') {
        printf("%c is a digit.\n", ch);
    } else {
        printf("%c is not an alphabet character.\n", ch);
    }

    return 0;
}

Edge Cases & Gotchas

When implementing character checks, several edge cases should be considered:

  • Input Validation: Ensure that the input is indeed a single character. If the user inputs more than one character, the program should handle this gracefully, perhaps by prompting the user again.
  • Whitespace Characters: Spaces, tabs, and newline characters should be identified and handled appropriately, as they do not fall into the vowel or consonant category.
  • Unicode Characters: If your application needs to handle internationalization, consider how to deal with characters outside the basic ASCII range.

Performance & Best Practices

When writing programs in C, following best practices can greatly enhance performance and maintainability:

  • Use Functions: Encapsulate the logic for checking vowels and consonants in a function. This promotes code reuse and clarity.
  • Optimize Input Handling: Use functions like getchar for single character input, which may simplify the reading process.
  • Comment Your Code: Ensure that your code is well-commented to improve readability and maintainability, especially when working in teams.

Conclusion

In this tutorial, we explored how to check if a character is a vowel or a consonant in C. We covered the basic implementation, extended functionalities, and best practices to ensure robust code.

  • Understanding the difference between vowels and consonants is essential for various applications.
  • Input validation is crucial to handle edge cases effectively.
  • Following best practices can improve code quality and maintainability.
Check if the character is a vowel or a consonant 2 Check if the character is a vowel or a consonant 3

S
Shubham Saini
Programming author at Code2Night — sharing tutorials on ASP.NET, C#, and more.
View all posts →

Related Articles

Mastering Format Specifiers in C: A Complete Guide with Examples
Dec 09, 2023
Introduction to C: A Step-by-Step Guide with Examples
Dec 09, 2023
Control Statements in C
Dec 09, 2023
Mastering Strings in C: A Complete Guide with Examples
Dec 09, 2023
Previous in C
Mastering Strings in C: A Complete Guide with Examples
Next in C
Assigment-folder(To find the biggest number in a 1D array in C,)
Buy me a pizza

Comments

On this page

More in C

  • Mastering Unconditional Statements in C: A Complete Guide wi… 21439 views
  • Understanding C: A Complete Guide with Examples 5147 views
  • Mastering Unconditional Statements in C: A Complete Guide wi… 4196 views
  • Mastering 2-D Arrays in C: A Complete Guide with Examples 3914 views
  • Mastering Input/Output Functions in C: A Complete Guide with… 3343 views
View all C posts →

Tags

AspNet C# programming AspNet MVC c programming AspNet Core C software development tutorial MVC memory management Paypal coding coding best practices data structures programming tutorial tutorials object oriented programming Slick Slider StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1770
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blog Archive
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
  • SEO Analyzer
Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • SQL Formatter
  • Diff Checker
  • Regex Tester
  • Markdown to HTML
  • Word Counter
More Tools
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Base64 Encoder
  • JWT Decoder
  • UUID Generator
  • Image Converter
  • PNG to ICO
  • SEO Analyzer
By Language
  • Angular
  • Angular js
  • ASP.NET
  • Asp.net Core
  • ASP.NET Core, C#
  • ASP.NET MVC
  • ASP.NET Web Forms
  • C
  • C#
  • C#, ASP.NET Core, Dapper
  • C#, ASP.NET Core, Dapper, Entity Framework
  • DotNet
  • General Web Development
  • HTML, CSS
  • HTML/CSS
  • Java
  • JavaScript
  • JavaScript, HTML, CSS
  • JavaScript, Node.js
  • Node.js
  • Python
  • Python 3.11, Pandas, SQL
  • Python 3.11, SQL
  • Python 3.11, SQLAlchemy
  • Python 3.11, SQLAlchemy, SQL
  • Python 3.11, SQLite
  • React
  • Security
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ·  Terms
Translate Page
We use cookies to improve your experience and analyze site traffic. By clicking Accept, you consent to our use of cookies. Privacy Policy
Accessibility
Text size
High contrast
Grayscale
Dyslexia font
Highlight links
Pause animations
Large cursor