Hey guys,
I'm trying to scan 3 columns of data from a .txt file. One of the columns does not contain some data. Below is an example of the .txt file.
Code:
1 5
2 6
3 7
4 7
5 8 2
6 9 5
7 0 6
8 2 27
9 1 8
10 5 9
11 67 0
12 8 1
The problem is when I try to display it in the program, it places a value in those blank cells. For example, the first row is "1 5 blank" but the program will display it as "1 5 2" because it places the "3rd" value in that cell. How can I make it so it skips it?
Here is my code thus far:
Code:
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <stdlib.h>
int main(void){
FILE *infile, *outfile;
float xdata[99], ydata[99], zdata[99];
int lcv;
infile = fopen("data.txt", "r");
if (infile == NULL){
printf("unable to open file");
} else {
for(lcv=0; lcv <=21; ++lcv){
fscanf(infile, "%f %f %f",&xdata[lcv],&ydata[lcv],&zdata[lcv]); //read
printf("%10.0f %10.2f %10.2f\n",xdata[lcv],ydata[lcv],zdata[lcv]);
}
fclose(infile);
}
}