0

I've been trying to read a data file with the following lines of code, but it doesn't ever start to read any and I don't know what's the problem:

#include <stdio.h>
#include <stdlib.h>
main()
{
    FILE * entrada, * salida;
    double *x, *y;
    double *z;
    int i=0,j=0,n=0;

    entrada=fopen("salidaIntegral.txt", "r");
    salida=fopen("Integral.txt", "w");

    fscanf(entrada,"%lf %lf", &x[i], &y[i]);
    printf("%lf %lf\n", x[i], y[i]);
    i++;
    while(feof(entrada)!=0)
    {
        fscanf(entrada, "%lf %lf", &x[i], &y[i]);
        printf("%lf %lf\n", x[i], y[i]);
        i++;
    }

The .txt file is in the same folder as the .c file.

  • 1
    the .txt should be where the executable is or you should specify the path to the text file from wherever the executable lives – Joe Dec 30 '20 at 19:27
  • 1
    `double *x, *y;` are not pointing to any valid memory. But before then, you must check that the files really did open. – Weather Vane Dec 30 '20 at 19:27
  • 1
    A [useful link](https://stackoverflow.com/q/5431941/1707353). – Jeff Holt Dec 30 '20 at 19:35

1 Answers1

0

It was a Weather Vane said, the double *x, *y were not pointing at anything, now it's solved