I’m new to C and I’m trying to figure out how to send the output of one program to another for processing.… or PIPE it.
Eg. ./foo | ./boo
foo - reads data from an external source every 100ms and writes it to stdout.
boo - reads data from stdin, does some simple calculations and writes it to stdout,
(I don't have access to foo, but it writes a float value every 100ms on a new line.)
I have it working, however after every couple of hundred entries… there is a 2 second pause...
so it spits out about 200 lines, 2 second pause, 200 lines, 2 second pause. etc..
Is there a buffer I need to be aware off?
Here is the code for boo;
#include <stdio.h>
float input;
float value;
while (1)
{
input = scanf("%f", &value);
{do stuff here}
printf("result %f \n ", input);
fflush(stdout);
}
return 0;
}
EDIT I found the issue, foo had a loop for the 100ms delay. when piping this into boo it was somehow getting grouped together. Removing this loop fixed the issue