#include #include #include #include #include #include #define PANIC(a) do { \ perror(a); \ if (temp_name) unlink(temp_name);\ exit(1);\ } while(0) int main() { FILE *command,*data; char *temp_name; double a,b; int i; if ((temp_name = tmpnam((char *) 0)) == 0) PANIC("tmpnam failed"); if(mkfifo(temp_name, S_IRUSR | S_IWUSR) != 0) PANIC("mkfifo failed"); command = popen("gnuplot","w"); fprintf(command,"plot \"%s\" with lines\n",temp_name); fflush(command); data = fopen(temp_name,"w"); for (i=0; i<20; i++) { a = i/10.0; b = sin(a); fprintf(data,"%f %f\n",a,b); } fclose(data); fprintf(stderr,"press enter to continue..."); fflush(stderr); getchar(); fprintf(command,"plot \"%s\" with lines\n",temp_name); fflush(command); data = fopen(temp_name,"w"); for (i=0; i<20; i++) { a = i/10.0; b = cos(a); fprintf(data,"%f %f\n",a,b); } fclose(data); fprintf(stderr,"press enter to continue..."); fflush(stderr); getchar(); fclose(command); unlink(temp_name); return 0; }