Skip to content

Instantly share code, notes, and snippets.

@DouglasAllen
Created February 11, 2017 11:46
Show Gist options
  • Save DouglasAllen/03eb378f17e6af51d50593763da28bde to your computer and use it in GitHub Desktop.
Save DouglasAllen/03eb378f17e6af51d50593763da28bde to your computer and use it in GitHub Desktop.
C main program takes a string input and counts the number of vowels and consonants.
//**************************************
// Name: vowels_consonants_counter.c
// Description:
// Consonants and Vowels Counter in C
// A sample program that will ask the user to enter a work or
// a sentence and then the program will count how many consonants and
// vowels in a given word or sentence by the user.
// Take note I am using Turbo C 2.0 For DOS as my C compiler in this program.
//
// If you have some questions please send me an email at jake.r.pomperada@gmail.com
// and jakerpomperada@yahoo.com.
// My mobile number here in the Philippines is 09173084360.
// By:
// Jake R. Pomperada
//
//
// Inputs:None
//
// Returns:None
//
// Assumes:None
//
// Side Effects:None
//**************************************
/* Consonants and Vowels Counter*/
/* Written By: Mr. Jake R. Pomperada, MAED-IT */
/* Date : November 25, 2015*/
/* Tools : Turbo C 2.0 For DOS*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <conio.h>
int main()
{
char strings[200];
int vowels=0,consonants=0,i=0;
//clrscr();
printf("Enter a word or sentence : ");
gets(strings);
while(strings[i] != '\0')
{
if (toupper(strings[i])=='A' || toupper(strings[i])=='E' ||
toupper(strings[i])=='I' || toupper(strings[i])=='O'||
toupper(strings[i])=='U')
vowels++;
if (toupper(strings[i])=='B' || toupper(strings[i])=='C' ||
toupper(strings[i])=='D' || toupper(strings[i])=='F'||
toupper(strings[i])=='G' || toupper(strings[i])=='H' ||
toupper(strings[i])=='J' || toupper(strings[i])=='K'||
toupper(strings[i])=='L' || toupper(strings[i])=='M' ||
toupper(strings[i])=='N' || toupper(strings[i])=='P'||
toupper(strings[i])=='Q' || toupper(strings[i])=='R' ||
toupper(strings[i])=='S' || toupper(strings[i])=='T'||
toupper(strings[i])=='V' || toupper(strings[i])=='W' ||
toupper(strings[i])=='X' || toupper(strings[i])=='Y' ||
toupper(strings[i])=='Z')
consonants++;
i++;
}
printf("\n\n");
printf("===== DISPLAY RESULTS =====");
printf("\n\n");
printf("Total Number of Vowels : %d. ", vowels);
printf("\n\n");
printf("Total Number of Consonants : %d.",consonants);
getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment