-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.c
More file actions
78 lines (59 loc) · 1.29 KB
/
string.c
File metadata and controls
78 lines (59 loc) · 1.29 KB
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
/*
C-program for Count the no. of vowels in given string using fork()
-------------------------------------------------------------------
*/
#include<stdio.h>
#include<string.h>
#include<unistd.h>
char str[60];
void count_words();
void count_vowels();
int main(void)
{
int pid;
int i,j;
printf("\nEnter a string::");
gets(str);
pid=fork();
if(pid==0)
{
printf("\nChild Process is Executing");
printf("\nProcess ID = %d\nParent ID = %d",getpid(),getppid());
count_words();
printf("\n\n");
}
else
{
printf("\nParent Process is Executing");
printf("\nProcess ID= %d\nParent ID= %d",getpid(),getppid());
count_vowels();
printf("\n\n");
}
return 0;
}
void count_words()
{
int i,j,k;
int count=1;
for(i=0;i<strlen(str);i++)
{
if(str[i]==32)
{
count++;
}
}
printf("\nThe No. of Words in String::%d",count);
}
void count_vowels()
{
int i,j,k;
int count=0;
for(i=0;i<strlen(str);i++)
{
if(str[i]=='a'||str[i]=='A'||str[i]=='e'||str[i]=='E'||str[i]=='i'||str[i]=='I'||str[i]=='o'||str[i]=='O'||str[i]=='u'||str[i]=='U')
{
count++;
}
}
printf("\nThe No. of Vowels in String :: %d",count);
}