0% found this document useful (0 votes)
5 views2 pages

Character Count in Strings

Uploaded by

rupamc50
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Character Count in Strings

Uploaded by

rupamc50
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <stdio.

h>

#include <ctype.h>

#include <string.h>

void countCharacters(const char *str, int *vowels, int *consonants, int *digits, int *whitespaces) {

*vowels = *consonants = *digits = *whitespaces = 0;

for (int i = 0; str[i] != '\0'; i++) {

char ch = tolower(str[i]);

if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {

(*vowels)++;

} else if (isalpha(ch)) {

(*consonants)++;

} else if (isdigit(ch)) {

(*digits)++;

} else if (isspace(ch)) {

(*whitespaces)++;

int main() {

char str[1000];

int vowels, consonants, digits, whitespaces;

printf("Enter a string: ");

fgets(str, sizeof(str), stdin);

countCharacters(str, &vowels, &consonants, &digits, &whitespaces);


printf("Vowels: %d\n", vowels);

printf("Consonants: %d\n", consonants);

printf("Digits: %d\n", digits);

printf("Whitespaces: %d\n", whitespaces);

return 0;

You might also like