Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the mistake in WRITE and READ?
    text
    copied!<p>This is a small C program concerning pipes and processes, The Father process will create 2 child processes, the first will read the numbers out of a chain, the second will read the letters. I started by asking for the WORD, I didnt add protection this is just a test, so lets say about 20 letters, then the father process will write the numbers in the first pipe, and the letters in the second pipe, then he will create a child using fork(), if he's the child , he will read the numbers from the first pipe, if he's the father, then he will create another child, to read the letters.</p> <pre><code># include &lt;stdio.h&gt; # include &lt;unistd.h&gt; # include &lt;string.h&gt; # include &lt;fcntl.h&gt; main() { printf("I am the father, I will create 2 sons, the first will read the numbers , the second will read the letters\n"); char * word; printf("please type the word: \n"); scanf("%s",word); printf("Now 2 pipes will be created\n"); int fd1[2]; int fd2[2]; pipe(fd1); pipe(fd2); printf("Now the father will write numbers in the first pipe, and letters in the second\n"); int i; char numbers[20]; int j=0; char caracters[20]; int k=0; for (i=0;i&lt;20;i++) { if(word[i]&gt;='0' &amp;&amp; word[i]&lt;='9') //if number { close(fd1[0]); //closing reading write(fd1[1],word[i],2); } else { close(fd2[0]); write(fd2[1],word[i],2); } } printf("The father has wrote in the 2 pipes, now its time for the sons\n"); int f=fork(); if(f==0) //first son { for(i=0;i&lt;20;i++) { close(fd1[1]); //closing writing read(fd1[0],numbers[j],strlen(numbers[j])+1); j++; } printf("first son read everything, he got %d Numbers\n", j); } else { f=fork(); if(f==0) { for(i=0;i&lt;20;i++) { close(fd2[1]); //closing writing read(fd2[0],caracters[k],strlen(caracters[k])+1); k++; } printf("second son read everything, he got %d caracters\n", j); } } </code></pre> <p>after compiling : </p> <pre><code>In function 'main': Line 25: warning: passing argument 2 of 'write' makes pointer from integer without a cast Line 31: warning: passing argument 2 of 'write' makes pointer from integer without a cast Line 41: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast Line 41: warning: passing argument 2 of 'read' makes pointer from integer without a cast Line 54: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast Line 54: warning: passing argument 2 of 'read' makes pointer from integer without a cast Line 60: error: expected declaration or statement at end of input </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload