I have a file.txt like:
4,3
3,2
5,1
6,5
Every line is a coordinate. For the first line, x1=4, y1 = 3. Then for the second line, x2=3, y2=2, and so on. The purpose of this method is to get the 4 coordinates inside the file and store them inside a variables or an array. I thought the best way was to create an array for x and another one for y, so we would have coordX[]
and coordY[]
. Since the file I must read will always contain only 4 coordinates, both arrays will have a size of [3].
The code I'm using right now is this:
void readFile(){
int x1, y1;
int coordX[3], coordY[3];
while (infile >> x1 >> y1){
//How to insert the coordinates into coordX[] and coordY[]?
}
}
As you can see, I don't know how to make the method insert the values of each coordinate into the array, is there a way to do it using an array? Or should I create int
variables x1, y1, x2, y2, and so on? Thanks in advance!