C 如何为每个元音创建一个过程?

C 如何为每个元音创建一个过程?,c,command-line,C,Command Line,我不熟悉流程。我读了很多书,但我并不真正理解它是如何工作的。我试图为字符字符串中的每个元音创建一个过程。我必须删除该字符串中的所有元音。我知道我必须用叉子,但我不知道怎么用。我试着写代码,但收到的是内核转储 #include <unistd.h> #include <stdio.h> #include <string.h> char sir[100]; int vocal(char x) { if(x=='a' || x=='e' || x==

我不熟悉流程。我读了很多书,但我并不真正理解它是如何工作的。我试图为字符字符串中的每个元音创建一个过程。我必须删除该字符串中的所有元音。我知道我必须用叉子,但我不知道怎么用。我试着写代码,但收到的是内核转储

#include <unistd.h>
#include <stdio.h> 
#include <string.h>

char sir[100];

int vocal(char x)  
{

  if(x=='a' || x=='e' || x=='i' || x=='o' || x=='u' || x=='A'|| 
  x=='E' || x=='I' || x=='O' || x=='U')
return 1;
return 0;

}
int main(){

printf("Read the text: \n");
read(1,sir,100); // file descriptor is 1;
pid_t a_Process;

for(int i=0;i<strlen(sir);i++)
{

  if(vocal(sir[i])==1)
    {
    a_Process=fork();
    for(int j=i;j<strlen(sir)-1;i++)
        sir[j]=sir[j+1];
}               

 }
 printf("%s",sir);
  return 0;
}
#包括
#包括
#包括
查尔先生[100];
int-vocal(字符x)
{
如果(x='a'| x='e'| x='i'| x='o'| x='u'| x='a'|
x=='E'| | x=='I'| | x=='O'| | x='U')
返回1;
返回0;
}
int main(){
printf(“读取文本:\n”);
读取(1,先生,100);//文件描述符为1;
pid_t a_过程;
对于(int i=0;i请尝试以下代码:

#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char sir[100];

int vocal(char x)
{
    if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u' ||
        x == 'A' || x == 'E' || x == 'I' || x == 'O' || x == 'U')
        return 1;
    return 0;
}

int main()
{
    int i, j, pid_status;

    printf("Read the text: \n");
    // read(1,sir,100); // file descriptor is 1;
    fgets(sir, 100, stdin);

    pid_t a_Process;

    for (i = 0; i < strlen(sir); i++)
    {
        if (vocal(sir[i]) == 1)
        {
            printf("detected a vowel\n");

            a_Process = fork();
            if (a_Process == -1)
            {
                fprintf(stderr, "Can't fork a process.\n");
                return 1;
            }

            if (a_Process)
            {
                printf("Starting a new child .... \n");
                for (j = i; j < strlen(sir) - 1; j++)
                    sir[j] = sir[j + 1];
            }

            // The following statement is needed such that
            // child process starts one after the other.
            if (waitpid(a_Process, &pid_status, 0) == -1)
            {
                printf("Error waiting for child process.\n");
            }
        }
    }
    printf("%s", sir);
    return 0;
}
#包括
#包括
#包括
#包括
#包括
查尔先生[100];
int-vocal(字符x)
{
如果(x='a'| | x='e'| | x='i'| | x='o'| | x='u'||
x='A'| | x='E'| | x='I'| | x='O'| | x='U')
返回1;
返回0;
}
int main()
{
int i、j、pid_状态;
printf(“读取文本:\n”);
//读取(1,先生,100);//文件描述符为1;
fgets(先生,100,标准输入法);
pid_t a_过程;
对于(i=0;iC/C++,它们是不同的语言,答案不同。对不起,C,我错了。