int test[2];
pipe(test);
FILE *to, *from;
if ((to = fdopen(test[1], "w")) == NULL)
return 1; //error: could not create stream
if ((from = fdopen(test[0], "r")) == NULL)
return 1; //error: could not create stream
fputs("test text", to);
char testBuff[5];
fgets(testBuff, 5, from);
puts(testBuff); //This should display 'test' in console - it does not, why?
The code above doesn't work - it displays nothing. I think that fgets(...) waits for input, but I used fputs(...) to send some text through pipe. How to make it work???
PS. This is just an example code - I just would like to know where do I think wrong?? Doesn't pipes work like some kind of buffers???
You can also see the problem in a bigger picture: http://www.daniweb.com/forums/thread119769.html