0

The data in the txt-file are just two columns with numbers, no labels (x-y coordinates).

#define _CRT_SECURE_NO_WARNINGS

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

typedef struct dataset{
    float x;
    float y;
} dataset;

int main(){

    dataset* coordinates;
    FILE* input;

    input = fopen("data.txt", "r");
    int i = 0;

    while (fscanf(input, "%e %e", &coordinates[i].x, &coordinates[i].y) == 2)
        i++;
    fclose(input);

    return 0;
}

Thank you for helping me out.

  • 5
    `dataset* coordinates;` is an uninitialized pointer. If you are using the `c` language which you appear to be doing you need to use malloc to preallocate your dynamic array before you attempt to put data into it. It will not grow as you add items so make sure you allocated enough at the start and check against the size to prevent overrunning your array. – drescherjm May 04 '21 at 23:31
  • This may help: [https://stackoverflow.com/questions/12990723/dynamic-array-of-structs-in-c](https://stackoverflow.com/questions/12990723/dynamic-array-of-structs-in-c) – drescherjm May 04 '21 at 23:37

0 Answers0