-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab 5 - String Character Analysis.c
98 lines (83 loc) · 2.04 KB
/
Lab 5 - String Character Analysis.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//Funtion to count Uppercase Alphabets in the string
int uppercase_alp(char* str)
{
int i=0;
int uppercase_alp=0;
while(str[i]!='\0')
{
if(str[i]>='A' && str[i]<='Z')
{
uppercase_alp++;
}
i++;
}
return uppercase_alp;
}
//Funtion to count Lowercase Alphabets in the string
int lowercase_alp(char* str)
{
int i=0;
int lowercase_alp=0;
while(str[i]!='\0')
{
if(str[i]>='a' && str[i]<='z')
{
lowercase_alp++;
}
i++;
}
return lowercase_alp;
}
//Funtion to count Vowels in the string
int vowels(char* str)
{
int i=0;
int vowel=0;
while(str[i]!='\0')
{
if(str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' ||
str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U')
{
vowel++;
}
i++;
}
return vowel;
}
//Funtion to count Digits in the string
int digits(char* str)
{
int i=0;
int digit=0;
while(str[i]!='\0')
{
if(str[i]>='0' && str[i]<='9')
{
digit++;
}
i++;
}
return digit;
}
void main()
{
char str[100];
int alp, ucalp, lcalp, vowel, digit, conso;
printf("Input the string : ");
fgets(str, sizeof str, stdin);
ucalp = uppercase_alp(str);
lcalp = lowercase_alp(str);
vowel = vowels(str);
digit = digits(str);
alp = lcalp+ucalp;
conso = alp-vowel;
printf("The total number of alphabets: %d\n", alp);
printf("The total number of digits: %d\n", digit);
printf("The total number of lower case alphabets: %d\n", lcalp);
printf("The total number of upper case alphabets: %d\n", ucalp);
printf("The total number of vowels: %d\n", vowel);
printf("The total number of consonants: %d\n", conso);
}