• GnuPlot problem from C ++

    From Ulul∞ Ululα@21:1/5 to All on Thu Apr 22 16:45:42 2021
    I state that I am a beginner with C and C ++ and my English is bad.

    I have to draw an f (x) on the Cartesian plane using C ++ and Gnuplot.
    I have:

    Windows 7 (64 bit)
    DEVC ++ Embarcadero compiler Version 6.3
    Gnuplot Version 5.2 patchlevel 8

    I call Gnuplot from a DevC ++ program by passing it the string "Frase"
    that contains the actions that Gnuplot will have to perform. When I
    start the program the graph of f(x) does not respect the information
    provided to Gnuplot with the string "Frase": for example the command
    "unset key" it is not respected as well as the "set grid" command.
    Why?

    Below is the listing of my test program and I thank in advance whoever
    succeeds to help me.


    This is my program:

    #include <string>
    #include <stdlib.h>
    #include <stdio.h>
    #include <math.h>

    int main(void) {

    char Frase[300]="plot [1:4] x*x+1;set grid;unset key;set title
    'f(x)';set xlabel 'X (m)';set ylabel 'Y (m)';set border \n";


    int Funzione;
    FILE * iFile, * oFile;

    Funzione=4;

    while (Funzione>0)
    {
    system("cls");
    printf("Inserisci Funzione (0=EXIT) : ");
    scanf("%d", &Funzione);

    if (Funzione>0)
    {
    oFile = fopen("comando_A.txt", "wt");
    fprintf(oFile,Frase);
    fprintf(oFile,"pause -1");
    fclose(oFile);
    system("gnuplot comando_A.txt");
    }

    }

    return(0);
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Hans-Bernhard_Br=c3=b6ker@21:1/5 to All on Thu Apr 22 23:13:11 2021
    Am 22.04.2021 um 16:45 schrieb Ulul� Ulul�:

    When I start the program the graph of f(x) does not respect the
    information provided to Gnuplot with the string "Frase": for example
    the command "unset key" it is not respected as well as the "set grid" command. Why?
    Because the pieces of your command string are in the wrong order. You
    put the cart before the horse.

    You should really begin by using gnuplot manually for a bit, before you
    go ahead trying to drive it from another program.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ulul Ulul@21:1/5 to HBBroeker@t-online.de on Fri Apr 23 11:50:46 2021
    On Thu, 22 Apr 2021 23:13:11 +0200, Hans-Bernhard Bröker <HBBroeker@t-online.de> wrote:

    Am 22.04.2021 um 16:45 schrieb Ulul? Ulul?:

    When I start the program the graph of f(x) does not respect the
    information provided to Gnuplot with the string "Frase": for example
    the command "unset key" it is not respected as well as the "set grid"
    command. Why?
    Because the pieces of your command string are in the wrong order. You
    put the cart before the horse.

    You should really begin by using gnuplot manually for a bit, before you
    go ahead trying to drive it from another program.

    Your phrase "You put the cart before the horse" was enlightening so I
    tried to move the horse in front of the cart and the program worked
    correctly!


    For the rest you are absolutely right: I have to practice more using
    Gnuplot manually.

    Thanks for the valuable advice and hello from Italy where I live!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Juan Humberto Artero Jaimez@21:1/5 to All on Mon May 10 08:19:56 2021
    El jueves, 22 de abril de 2021 a las 23:13:06 UTC+2, Hans-Bernhard Bröker escribió:
    Am 22.04.2021 um 16:45 schrieb Ulul� Ulul�:

    When I start the program the graph of f(x) does not respect the information provided to Gnuplot with the string "Frase": for example
    the command "unset key" it is not respected as well as the "set grid" command. Why?
    Because the pieces of your command string are in the wrong order. You
    put the cart before the horse.

    You should really begin by using gnuplot manually for a bit, before you
    go ahead trying to drive it from another program.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)