-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPROG29.C
31 lines (31 loc) · 896 Bytes
/
PROG29.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
//29. Write a program that accept a string and count the number of space character, tab character, new line character, and any other characters.
#include<stdio.h>
int main()
{
char str[30];
int i=0,sc=0,nlc=0,tc=0,osc=0;
printf("Enter the string (when you want to end,just type ! and press enter): \n");
while((str[i]=getchar())!='!')
{
switch(str[i])
{
case ' ':
sc++;
break;
case '\n':
nlc++;
break;
case '\t':
tc++;
break;
default:
osc++;
break;
}
}
printf("The total number of space character is %d\n",sc);
printf("The total number of new line character is %d\n",nlc);
printf("The total number of tab character is %d\n",tc);
printf("The total number of other character is %d\n",osc);
return 0;
}