-
problems compiling
I am having problems with this code. I cannot figure out where my problem is.
here is the source code
Code:
//Preprocessing directives
#include <stdio.h> /* header file */
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "calc_stats.h"
// function prototypes
//opens the input and output files
void open_files(FILE **fp_in, char filename_in[], FILE **fp_out, char filename_out[]);
//gets the data inputs from a string that is read from the data file
void get_tokens(char string1[], double data_array[][12], double stats[][6], int row);
//calculate the results
void calc_stats(double data_array[][12], double stats[][6], int number_rows);
//write the output
void write_Data(FILE *fp_out, double data_array_transposed[][10], double stats_transposed[][10], int array_rows, int array_columns);
int main(void)
{
char filename_in[35] = "test_data.txt" ;//initialize to test_data.txt
char filename_out[35] = "test_stats.txt";
char string1[90];
int array_rows = 10;
int array_columns = 12;
int stats_columns = 6;
int temp;
int j=0, k;
double data_array[10][12] = {0.0};
double data_array_transposed[12][10] = {0.0};
double stats[10][6];
double stats_transposed[6][10];
FILE *fp_in, *fp_out;
open_files(**fp_in, filename_in, **fp_out, filename_out);
while(fgets(string1, 90, fp_in) != NULL);
{
get_tokens(string1, data_array, stats, array_rows);
calc_stats(data_array, stats, array_rows);
}
for(j=0;j<array_rows;j++);
{
for(k=0;k<array_columns;k++);
data_array_transposed[k][j] = data_array[j][k];
}
for(j=0;j<array_rows;j++);
{
for(k=0;k<stats_columns;k++);
stats_transposed[k][j] = stats [j][k];
}
temp = array_rows;
array_rows = array_columns;
array_columns = temp;
write_data(fp_out, data_array_transposed, stats_transposed, array_rows, array_columns);
fclose(fp_in);
fclose(fp_out);
printf("Exiting the program");
return 0;
}
void open_files(FILE **fp_in, char filename_in[], FILE **fp_out, char filename_out[])
{
*fp_in=fopen("filename_in","r");
if((*fp_in = fopen("filename_in", "r")) == NULL)
{
// display error message
printf("\nERROR: Input file not opened\n");
// abort
exit(EXIT_FAILURE);
}
*fp_out=fopen("filename_out","w");
if((*fp_in = fopen("filename_out", "w")) == NULL)
{
// display error message
printf("\nERROR: Input file not opened\n");
// abort
exit(EXIT_FAILURE);
}
}
void get_tokens(char string1[], double data_array[][12], double stats[][6], int row)
{
int k = 0;
char *tokenPtr;
tokenPtr = strtok(string1, " ");
while(tokenPtr != NULL)
{
data_array[row][k] = atof(tokenPtr);
tokenPtr = strtok(NULL, " ");
k++;
}
stats[row][0]=k;
}
void calc_stats(double data_array[][12], double stats[][6], int number_rows)
{
int j;
for(j=0; j<number_rows;j++)
{
calc_min(data_array, stats, number_rows);
calc_max(data_array, stats, number_rows);
calc_range(data_array, stats, number_rows);
calc_average(data_array, stats, number_rows);
calc_std_dev(data_array, stats, number_rows);
}
}
void write_data(FILE *fp_out, double data_array_transposed[][10], double stats_transposed[][10], int array_rows, int array_columns)
{
int j, k;
printf("\n\t\t************** Test Results ***************\n");
fprintf(fp_out, "\n\n\t************** Test Results ***************\n");
for(j=0;k<array_columns;j++)
{
printf("test%i",j+1);
fprintf(fp_out, "test%i", j+1);
printf("\n\n");
fprintf(fp_out, "\n\n");
}
for(j=0; j<array_rows; j++)
{
for(k=0; k<array_columns;k++)
if(data_array_transposed[j][k]==0)
{
printf(" ");
fprintf(fp_out, " ");
}
else
{
printf("%6.2lf", data_array_transposed[j][k]);
fprintf(fp_out, "%6.2lf", data_array_transposed[j][k]);
}
}
printf("\n");
fprintf(fp_out, "\n");
printf("\n\t\t********* Number tests in each set *********\n");
fprintf(fp_out, "\n\t\t********* Number tests in each set *********\n");
for(j=0;j<array_columns;j++)
{
printf("%6.2lf", stats_transposed[0][j]);
fprintf(fp_out, "%6.2lf", stats_transposed[0][j]);
}
printf("n\n\t\t*********** Minimum for each set ***********\n");
fprintf(fp_out, "n\n\t\t*********** Minimum for each set ***********\n");
for(j=0; j<array_columns;j++)
{
printf("%6.2lf", stats_transposed[1][j]);
fprintf(fp_out, "%6.2lf", stats_transposed[1][j]);
}
printf("\n\n\t\t*********** Maximum for each set ***********\n");
fprintf(fp_out, "\n\n\t\t*********** Maximum for each set ***********\n");
for(j=0;j<array_columns;j++)
{
printf("%6.2lf", stats_transposed[2][j]);
fprintf(fp_out, "%6.2lf", stats_transposed[2][j]);
}
printf("\n\n\t\t************ Range for each set ************\n");
fprintf(fp_out, "\n\n\t\t************ Range for each set ************\n");
for(j=0;j<array_columns;j++)
{
printf("%6.2lf", stats_transposed[3][j]);
fprintf(fp_out, "%6.2lf", stats_transposed[3][j]);
}
printf("\n\n\t\t*********** Average for each set ***********\n");
fprintf(fp_out, "\n\n\t\t*********** Average for each set ***********\n");
for(j=0;j<array_columns;j++)
{
printf("%6.2lf", stats_transposed[4][j]);
fprintf(fp_out, "%6.2lf", stats_transposed[4][j]);
}
printf("\n\n\t\t******** Standard Dev for each set ********\n");
fprintf(fp_out, "\n\n\t\t******** Standard Dev for each set ********\n");
for(j=0;j<array_columns;j++)
{
printf("%6.2lf", stats_transposed[5][j]);
fprintf(fp_out, "%6.2lf", stats_transposed[5][j]);
}
printf("\n");
fprintf(fp_out, "\n");
}
I have not included the calc_stats.h file with this, I can if need be. The errors I'm getting are
rahn1.cpp(68) : error C2100: illegal indirection
rahn1.cpp(68) : error C2100: illegal indirection
rahn1.cpp(68) : error C2664: 'open_files' : cannot convert parameter 1 from 'struct _iobuf' to 'struct _iobuf ** '
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
rahn1.cpp(91) : error C2065: 'write_data' : undeclared identifier
rahn1.cpp(156) : error C2373: 'write_data' : redefinition; different type modifiers
I'm just looking for some help. As of right now, I'm completely lost. Thanks.
-
try removing the pointer to pointers in the functions. change ** to * and then fp_in = open() to solve the illegal indirection (this is just a guess)
as for write_data, in the prototype you capitalized the D (write_Data) but you didn't capitalize it in the definition.
-
I'm having some problems, could you post the header file too plz.
I solved the last two errors:
Change write_data to write_Data.
--EDIT--
You're fast misplaced! Too fast! :D
-
Thanks y'all! I got it figured out. I'm having 1 other problem, but I'm going to make it a seperate thread.