Hi,

I just started unix programming .
below are the two files i am using for reading/ writing from/to a named pipe called RNP.

read.c is run on one terminal and write.c is run on other terminal.

write.c is accepting the input , but read.c is not reading the input from PIPE.

i could not find out the where it is going wrong.

read.c

#include "uni_comman.h" // has all the required .h files
#include <stdio.h>

int main( int argc , char **argv)
{
        char buf[30];
        int fd,n,rv,nob;

        #if 0
        if ((rv = mkfifo("RNP",0666))== -1 ) {
                perror("mkfifo:");
                exit(1);
        }
        #endif

        if (rv = open("RNP",0666)== -1) {
                perror("open:");
                exit(1);
        }
        printf("rv = %d\n", rv);
        while( 1 ) {
                nob = read(rv,buf,sizeof(buf));
                printf(" nob : %d \n", nob);
                printf(" %s \n", buf );
        }

        exit(0);

}

write.c

#include "uni_comman.h"
#include <stdio.h>

int main( int argc , char **argv)
{
        char buf[30],*ptr;
        int fd,n,rv,nob;

        if ((rv = mkfifo("RNP",0666))== -1 ) {
                perror("mkfifo:WNP");
                exit(1);
        }

        if (rv = open("RNP",0666)== -1) {
                perror("open:");
                exit(1);
        }
        printf("enter sth...\n");
        while( (ptr = fgets(buf,sizeof buf , stdin ))!= NULL ){

                nob = write(rv,buf,sizeof(buf));
                printf(" nob written : %d \n", nob);
        }

        close(rv);
        exit(0);

}

Hi,

I just started unix programming .
below are the two files i am using for reading/ writing from/to a named pipe called RNP.

read.c is run on one terminal and write.c is run on other terminal.

write.c is accepting the input , but read.c is not reading the input from PIPE.

i could not find out the where it is going wrong.

read.c

#include "uni_comman.h" // has all the required .h files
#include <stdio.h>

int main( int argc , char **argv)
{
        char buf[30];
        int fd,n,rv,nob;

        #if 0
        if ((rv = mkfifo("RNP",0666))== -1 ) {
                perror("mkfifo:");
                exit(1);
        }
        #endif

        if (rv = open("RNP",0666)== -1) {
                perror("open:");
                exit(1);
        }
        printf("rv = %d\n", rv);
        while( 1 ) {
                nob = read(rv,buf,sizeof(buf));
                printf(" nob : %d \n", nob);
                printf(" %s \n", buf );
        }

        exit(0);

}

write.c

#include "uni_comman.h"
#include <stdio.h>

int main( int argc , char **argv)
{
        char buf[30],*ptr;
        int fd,n,rv,nob;

        if ((rv = mkfifo("RNP",0666))== -1 ) {
                perror("mkfifo:WNP");
                exit(1);
        }

        if (rv = open("RNP",0666)== -1) {
                perror("open:");
                exit(1);
        }
        printf("enter sth...\n");
        while( (ptr = fgets(buf,sizeof buf , stdin ))!= NULL ){

                nob = write(rv,buf,sizeof(buf));
                printf(" nob written : %d \n", nob);
        }

        close(rv);
        exit(0);

}

well ok.

i solved the problem.

brackets are not enclosed for open call.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.