Linux command-line redirection with 2 c-files -


i'm new piping i/o functions within linux. 2 c-files made, first sends data:

    #include <stdio.h>     #include <stdlib.h>     #include <time.h>     #include <unistd.h>      int main(int argc, char* argv[])     {          int = 0;           for(;;)          {              printf("\nsent number: %d",i);              i++;              sleep(1);              fflush(stdout);          }      return 0; } 

the second files receives printed number , displays it:

    #include <stdio.h>     #include <stdlib.h>     #include <time.h>     #include <unistd.h>  int main(int argc, char* argv[]) {         int x;      for(;;)     {         scanf("%d",&x);         printf("received number: %d\n",x);         sleep(1);         fflush(stdout);     }      return 0; } 

finally try redirect data first file second with:

./send_test.out | ./rcv_test.out 

the terminal prints repeatedly: "received number: 0", doing wrong? also, how can have terminal windows both programs running simultaneously while directing output sender receiver?

thanks in advance

you not "sending" number in format the receiver can understand.

try removing text except %d sender's formatting string.

also, should check return value of scanf() before relying on it.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -