Prpgram to count vowels in given string by using vfork method (use of Vfork Function in c)


#include "stdio.h"
#include "dirent.h"
int main()
{
int j,n,a,i,e,o,u;
char str[50];
a=e=i=o=u=0;
pid_t pid;
if((pid=vfork())<0)
{
perror("FORK ERROR");
exit(1);
}
if(pid==0)
{
printf("Enter the String to count vowels:");
gets(str);
_exit(1);
}
else
{
n=strlen(str);
for(j=0;j
{
if(str[j]=='a' || str[j]=='A')
a++;
else if(str[j]=='e' || str[j]=='E')
e++;
else if(str[j]=='i' || str[j]=='I')
i++;
else if(str[j]=='o' || str[j]=='O')
o++;
else if(str[j]=='u' || str[j]=='U')
u++;
}
printf("Vowels Counting");
printf("Number of A : %d",a);
printf("Number of E : %d",e);
printf("Number of I : %d",i);
printf("Number of O : %d",o);
printf("Number of U : %d",u);
printf("Total vowels : %d",a+e+i+o+u);
exit(1);
}
}

No comments:

Post a Comment