I'm trying to write a short code that will take in a string of text, and tell me how many vowels are in it, with the information being passed between a parent and child process using pipes (I am only testing for "a" at the moment until I get that working, then I'll finish the others).
I keep getting segmentation fault (Core Dumped).
Would you mind checking out my code and pointing me in the right direction?
Thank you in advance for any and all assistance.
#include <stdio.h>
#define READ 0
#define WRITE 1
char* phrase;
main ()
{
int fd [2], vCount;
char message[80];
int i, j, k = 0;
char c;
char vowels[80];
printf ("Enter a phrase up to a maximum of 80 characters.\n");
//phrase = gets (message);
while (i < 80 && (c = getchar()) != '\n')
{
message[i] = c;
switch(c)
{
case 'a':
vowels[j] = c;
j++;
}
i++;
}
pipe (fd);
if (fork () == 0)
{
close(fd[READ]);
write (fd[WRITE], vowels, (j + 1));
close (fd[WRITE]);
}
else
{
close (fd[WRITE]);
vCount = read (fd[READ], vowels, 80);
printf ("There are %d vowels. They are: %s\n", vCount, vowels);
close (fd[READ]);
}
}