タイトルで言うように、私は2人の息子が母音(son2)と子音(son2)を研究するプログラムをC言語で作成しようとしています。研究を行うために、私は母音を最初に研究する2つの関数を使用し、子音を研究するために2番目の関数を使用します。私は、コマンドラインからプログラム3以上のファイルに与える :C fork()の母音と子音の研究
-1°母音と子音
-2°の組み合わせを格納したファイルは、すべて保存されたファイルであるに母音は
を設立-3°すべての子音は、プログラムがエラー/警告なしでコンパイルされているが、それは正しく、研究を完了していない、ここでは一例である
を設立保存されたファイルである。
-firstファイル:qwerty配列
- セカンドファイル:EY
- 第3ファイル:QR私はのために事前にそれを
gcc c.c
./a.out c.txt v.txt b.txt
感謝をコンパイルするには、これらのコマンドを使用し
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
int test_vowel(char ch)
{
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
ch == 'y')
return(1);
else
return(0);
}
int main(int argc, char *argv[])
{
char c, d;
int s;
pid_t pid1 = 10, pid2 = 10;
if((pid1 = fork()) < 0)
{
printf("Error in the creation of the first fork\n");
_exit(0);
}
if(pid1 > 0)
{
if((pid2 = fork()) < 0)
{
printf("Error in the creation of the second fork\n");
_exit(0);
}
}
int input = open(argv[1],O_RDONLY);
int output1 = open(argv[2],O_RDWR | O_CREAT | O_TRUNC, 0666);
int output2 = open(argv[3],O_RDWR | O_CREAT | O_TRUNC, 0666);
if(pid2 == 0)
{
while((s = read(input, &c, 1)) != 0)
{
if(test_vowel(tolower(c)) == 1)
{
printf("I've read a vowel = %d\n", d);
write(output1, &c, 1);
}
}
}
if(pid1 == 0)
{
while((s = read(input, &d, 1)) != 0)
{
if(test_vowel(tolower(d)) == 0)
{
printf("I've read a consonant = %d\n", d);
write(output2, &d,1);
}
}
}
}
助けて!あなたが任意の特定の値にpid1
またはpid2
を初期化しないデビッド・C.ランキン
'tolower(ch)'を使うと、if条件の数を2倍に減らすことができます。ちょうど 'if(isalpha(ch)){ch = tolower(ch); if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')return 1;それ以外の場合は2を返します。 } '(またはあなたが子音や母音を示したいもの) –
私の本は決してこの機能を引用していないと言わなければならない、チップのおかげで! – Allen