For an assignment I have I need to make an array to hold the values of about 12000 lines of data. There are 4 columns of data but I only need the fourth. My teacher told the class to use this syntax to do this:
fscanf (infile, "%*s%*s%*s%f", &data_val[ i ] ) ;
The first three variables are suppressed and the fourth taken and put into the index. My question is how can I make a loop that will start indexing at the right place and continue to do that until there is none left. Here is my program thus far:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
int main ( )
{
/*Opens files to be used*/
FILE *fptr1, *fptr2;
fptr1=fopen("a13.dat", "r");
fptr2=fopen("a13.txt", "w");
/*Declares variables*/
int n=0;
float dataval[12000], i;
char string1[14], buffer[256], string2[14];
/*Loop for displaying headers*/
while(string1[n]!=string1[17])
{
fgets (buffer, 256, fptr1);
puts (buffer);
fputs(buffer, fptr2);
n++;
}
/*Loop for reading in values*/
n=18;
while(string2[n]>=string2[18] && !feof(fptr1))
{
fscanf(fptr1, "%*s%*s%*s%f", &dataval[i]);
printf("%*s%*s%*s%f", dataval);
i++;
n++;
}
}
The first loop is to read in a header section that is 17 rows, and displays it to the screen and also writes it to a file. This loop works, it is the second loop I am struggling with.
Here is a sample of how the data is arranged:
"
"Source File: C:\PROGRA~1\PSLOG\195RIDE.PL1
"ID: IE Group 4 Bike Stress friday XR440 12 bi
"Ch1 lbl/scl: Start/Stop /A
"Ch2 lbl/scl: input voltage signal /-5.000 05.000
"Ch3 lbl/scl: Off /C
"Ch4 lbl/scl: Off /C
"Rate (mins): 0.0000833333324 Bat: 8.8
"First: Fri 20-Nov-1998 10:38:47am
"Last: Fri 20-Nov-1998 10:39:40am
"Transferred: Fri 20-Nov-1998 10:42:37am
"Eq. PC time: Fri 20-Nov-1998 10:42:38AM
"
Date,Time,Ch1:Deg F,Ch2:
11/20/1998 10:38:47.000 -4.989 0.238
11/20/1998 10:38:47.005 -4.989 0.231
11/20/1998 10:38:47.010 -4.989 0.228
11/20/1998 10:38:47.015 -4.989 0.231
11/20/1998 10:38:47.020 -4.989 0.228