I am trying to initialize the gnuplot using C interface, following this example:
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
void plot(float xValues[], float yValues[], int NUM_POINTS) {
char* commandsForGnuplot[] = { "set title \"TITLEEEEE\"", "plot 'data.temp'", "fflush(gnuplotPipe)" };
FILE* temp = fopen("data.temp", "w");
FILE* gnuplotPipe = _popen("gnuplot -persistent", "w");
int i;
for (i = 0; i < NUM_POINTS; i++)
{
fprintf(temp, "%lf %lf \n", xValues[i], yValues[i]); //Write the data to a temporary file
}
fclose(temp);
for (i = 0; i < 3; i++)
{
fprintf(gnuplotPipe, "%s \n", commandsForGnuplot[i]); //Send commands to gnuplot one by one.
}
}
void main(){
float a[] = {0, 1, 2, 5, 8};
float b[] = {0, 1, 2, 3, 4};
plot(a, b, 5);
}
For some reason, the plot does not show up. What I should correct?
Edit
Found out that the prompt window shows the following message:
"'gnuplot' is not recognized as an internal or external command, operable program or batch file."
Edit2 Following @theozh added the path to gnuplot.exe and solved the problem