Take values from file.txt

0

Good morning, I have a little doubt. I have to load some data from a txt file with three columns, the first is not necessary to keep it.

The size of the vectors to be of 15000 samples, should I make the length of these as dynamic vectors?

I attach the part of the code.

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>

#define MUESTRA 15000


FILE *fd,*fl;
char c,d;


int main(){


    int L, N, H, M; // longitud, pnts vecinos, umbral, nº pulsos encoder
    int i,j,c,*intensidad,*contaje,cont=0;
    intensidad = (int*)malloc(MUESTRA*sizeof(int));
    contaje = (int*)malloc(MUESTRA*sizeof(int));
    char aux;
    char temp[20];
    char direccion [] ="C:\Users\Usuario\Desktop\Trabajo Programacion\Senyales trabajo 1\configuracion.txt";
    char direccion2 [] ="C:\Users\Usuario\Desktop\Trabajo Programacion\Senyales trabajo 1\senyal1.txt";
    fd = fopen(direccion,"r");
    fl = fopen(direccion2,"r");

    if(fd == NULL){
        printf("Error");
        return 1;
    }

    if(fl == NULL){
        printf("Error");
        return 1;
    }

    fscanf(fd, "%d", &L);
    fscanf(fd, "%d", &N);
    fscanf(fd, "%d", &H);
    fscanf(fd, "%d", &M);


    for (i=0; i<MUESTRA; i++)
    {
        fscanf(fl, "%d", *(intensidad+i));
        fscanf(fl, "%d", *(contaje+i));

        printf("%d\n",*(intensidad+i));
        printf("%d\n",*(contaje+i));

    }

    intensidad = (int*)realloc(intensidad,MUESTRA*sizeof(int));
    contaje = (int*)realloc(contaje,MUESTRA*sizeof(int));

    printf("%d \n",L);
    printf("%d\n",N);
    printf("%d\n",H);
    printf("%d\n",M);

    fclose(fd);
    fclose(fl);
    return 0;
}
    
asked by AdriánD 19.12.2017 в 16:26
source

0 answers