bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

pc012.c (1507B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 12 Dec 2025
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /* Write a C function that receives a string (character array) and uses
      9 pointers to count and return the total number of vowels and consonants in that string. */
     10 /* Author: Amit Dutta, Date: 02-12-2025 */
     11 
     12 #include <stdio.h>
     13 #include <ctype.h>
     14 
     15 void charCounter(char[], int *, int *);
     16 
     17 int main()
     18 {
     19     char str[101];
     20     int vowelCount, consonantCount;
     21     printf("Enter the string (Max: 100 character): ");
     22     if (fgets(str, sizeof(str), stdin) == NULL)
     23     {
     24         printf("Error reading input.\n");
     25         return 1;
     26     }
     27     charCounter(str, &vowelCount, &consonantCount);
     28     printf("\nVowel Count: %d", vowelCount);
     29     printf("\nConsonant Count: %d", consonantCount);
     30     printf("\nTotal Character: %d", vowelCount + consonantCount);
     31     return 0;
     32 }
     33 
     34 void charCounter(char str[], int *vowelCount, int *consonantCount)
     35 {
     36     int tempVowelCount = 0, tempConsonantCount = 0;
     37     while (*str != '\0')
     38     {
     39         char ch = tolower(*str);
     40         if (isalpha(ch))
     41         {
     42             if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
     43             {
     44                 tempVowelCount++;
     45             }
     46             else
     47             {
     48                 tempConsonantCount++;
     49             }
     50         }
     51         str++;
     52     }
     53 
     54     *vowelCount = tempVowelCount;
     55     *consonantCount = tempConsonantCount;
     56 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror