how do you take data from a file and inputted into an array if the data in the file were to look like this
1 1 1
2 1 1
3 1 1
4 1 1
5 1 1
6 1 1
...and
(column 1) index of the array, i -- an integer;
(column 2) value of element iin array x, x[i] -- a double value
(column 3) value of element i in array y, y[i]
so i for example when i do my first loop i should get this
x[1]=1 y[1]=1
and my second loop
x[2]=1 y[2]=1.
i know how to open file and work with loops, but i dont know how to make my first column the index of the array, and my second column the value of the element and so on. so any help would be appreciated.
so it should look something like this
Code:
#include <stdio.h>
int main()
{
FILE *inp;
int input_status;
int n;
inp = fopen("xy.txt", "r"); //opens files
input_status = fscanf(inp, "%d", &n); //takes digits
while (input_status != EOF) //loop repeats till end of file
{
printf( "%d\n",n);// instead of this i need something that assigns it to i, and to the value of the element in array x, x[i]
input_status = fscanf(inp, "%d", &n);
}
fclose(inp);
}