Here's my program as it stands now. It's supposed to read in values from a file, which is supplied on the command line. If the values start with an alpha, they are ignored. Otherwise, they are supposed to be converted to floats, and then averaged.
Here's the code, currently giving me syntax errors on the bold line:
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char *argv[]){
FILE* dataFile;
FILE* outputFile;
char stringArray[1000][80];
float floatArray[1000];
int i = 0;
int j = 0;
int number_of_lines;
int number_of_floats;
float sum_of_floats;
float average;
dataFile = fopen(argv[1], "rb");
if (dataFile == NULL){
fputs("File error", stderr);
exit(1);
}
while (1){
fscanf(dataFile, "%s", stringArray[i]);
if (stringArray[i][0] == EOF){
break;
}
i++;
}
fclose(dataFile);
number_of_lines = (i+1);
for (i=0; i<number_of_lines; i++){
if (isalpha(stringArray[i][0])){
i++;
}
else{
floatArray[j] = strtof(&stringArray[i],&&stringArray[i][79]);
j++;
}
}
number_of_floats = (j+1);
for (i=0; i<number_of_floats; i++){
sum_of_floats += floatArray[i];
}
average = ((sum_of_floats)/((float)(number_of_floats));
printf("%f", average);
fclose(dataFile);
getch();
return 0;
}
The syntax errors are:
Code:
51 C:\Documents and Settings\Don\My Documents\Online Assignments\autocorrelation.c syntax error before '[' token
61 C:\Documents and Settings\Don\My Documents\Online Assignments\autocorrelation.c syntax error before ';' token
51 C:\Documents and Settings\Don\My Documents\Online Assignments\autocorrelation.c label `stringArray' used but not defined
And that's before I even access the file, which is of the form:
Code:
C HERE'S A COMMENT
C HERE'S ANOTHER COMMENT
234.5
-123.67
0.000
10.10
.
.
.
Am I just doing something completely stupid or what?