Never mind. I figured it out. For whatever reasons, I needed a newline in the following line code..
Code:
(void)fprintf(command, "plot \"%s\" ", "sin(5)");
So I changed the code to the following.
Code:
(void)fprintf(command, "%s\n", "plot sin(5)");
Also, I needed to have the follow so the plotter wouldn't exit right away..
Code:
while ((c = getchar()) != EOF)
;
Anyways, here is the complete solution..
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *command;
int c;
if ((command = popen("gnuplot", "w")) == NULL) {
(void)fprintf(stderr, "pipe error\n");
exit(1);
}
if (setvbuf(command, NULL, _IONBF, 0) != 0) {
(void)fprintf(stderr, "setbuf error\n");
exit(1);
}
(void)fprintf(command, "%s\n", "plot sin(5)");
fflush(command);
while ((c = getchar()) != EOF)
;
pclose(command);
exit(0);
}
Now, I have one more question. Why does gnuplot exit right away when I don't include
Code:
while ((c = getchar()) != EOF)
;
but something like ddd (the data display debugger) doesn't?