Thread: wts wrong in namepipe program

  1. #1
    kotin
    Join Date
    Oct 2009
    Posts
    132

    wts wrong in namepipe program

    i didt getting output in this nameppipe program. please anyone let me know error

    Code:
    #include<stdio.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <unistd.h>
    int main()
    {
    int i,j;
    char s[]="namedpipe",b[20];
    i=mkfifo("namedpipe",0666);
    j=open("namedpipe",O_RDWR);
    write(j,s,4);
    read(j,b,4);
    printf("%s\n",b);
    return 0;
    }

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Opening a pipe in "read-write" mode is not reliable (nor defined by POSIX, if I remember). You need to actually open the pipe twice, once in O_RDONLY mode and once in O_WRONLY mode.

    Also, your printf() string is not properly null-terminated.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    kotin
    Join Date
    Oct 2009
    Posts
    132
    Thanks for your suggestions

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c program that accepts and executes commands?
    By Cimposter in forum C Programming
    Replies: 3
    Last Post: 09-30-2009, 02:58 PM
  2. Replies: 2
    Last Post: 09-16-2009, 06:00 AM
  3. What is wrong with my code? My first program......
    By coreyt1111 in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2006, 02:03 PM
  4. Calendar Program. What am I doing wrong?
    By Sektor in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2004, 11:39 PM
  5. command line program, something wrong in the argv
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 09-26-2001, 09:36 AM