problems compiling

This is a discussion on problems compiling within the C Programming forums, part of the General Programming Boards category; I am having problems with this code. I cannot figure out where my problem is. here is the source code ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    4

    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.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    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 seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    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!
    Last edited by Kleid-0; 01-17-2005 at 02:48 PM.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    4
    Thanks y'all! I got it figured out. I'm having 1 other problem, but I'm going to make it a seperate thread.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 01:17 PM
  2. problems with including headers
    By l2u in forum C++ Programming
    Replies: 3
    Last Post: 07-23-2006, 09:06 AM
  3. Problem Compiling
    By Flakster in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 02:09 AM
  4. Linking problems, class problems
    By Kheila in forum C++ Programming
    Replies: 12
    Last Post: 11-22-2005, 01:47 AM
  5. compiling problems LNK2019 error
    By sugie in forum C++ Programming
    Replies: 2
    Last Post: 10-19-2005, 06:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21