C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-27-2009, 12:19 AM   #1
Registered User
 
Join Date: Oct 2009
Posts: 46
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;
}
nkrao123@gmail. is offline   Reply With Quote
Old 10-27-2009, 12:58 AM   #2
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,381
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.
__________________
"Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot
brewbuck is offline   Reply With Quote
Old 10-27-2009, 02:29 AM   #3
Registered User
 
Join Date: Oct 2009
Posts: 46
Thanks for your suggestions
nkrao123@gmail. is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
c program that accepts and executes commands? Cimposter C Programming 3 09-30-2009 02:58 PM
g++ compiler errors with vector class after installing/uninstalling libstlport Gatemaze C++ Programming 2 09-16-2009 06:00 AM
What is wrong with my code? My first program...... coreyt1111 C++ Programming 11 11-14-2006 02:03 PM
Calendar Program. What am I doing wrong? Sektor C++ Programming 3 01-17-2004 11:39 PM
command line program, something wrong in the argv Unregistered C Programming 1 09-26-2001 09:36 AM


All times are GMT -6. The time now is 12:10 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22