CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2012
    Posts
    0

    Question help me find the error?

    I am trying to read from a data file that has input as :

    12.0, 11, 123
    14.0, 12.1, 3


    and i want the program to read the data from the file and then make it into an array of structures and then print that array afterwards.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    	#define MAX_INPUT 1000
    
    int n =0;
    int i = 0;
    
    typedef struct
    {
    	double x[MAX_INPUT];
    	double y[MAX_INPUT];
    	double w[MAX_INPUT];
    }input_t;
    
    input_t input[MAX_INPUT];
    
    input_t
    read_int_array(int *n, input_t input[])
    {
    	int p=0;
    	int k=0;
    	double temp, temp3, temp2;
    	while (scanf("%lf %lf %lf", &temp, &temp2, &temp3)==3){
    		
    		input[k].x[k]=temp;
    		input[k].y[k]=temp2;
    		input[k].w[k]=temp3;
    		k++;
    		
    		p = *n;
    		p++;
    		*n = p;
    		
    	}
    	return input[MAX_INPUT];
    }
    
    void
    print_array(input_t input[])
    {	
    	int j=0;
    	for (j=0;j<n;j++)
    	{
    	printf("%.2lf meters east, ", input[j].x[j]);
    	printf("%.2lf meters north, ", input[j].y[j]);
    	printf("%.4lf Watts\n", input[j].w[j]);
    	}	
    }
    	
    int main(int argc, char **argv)
    {
    	input_t input[MAX_INPUT];
    	input[MAX_INPUT] = read_int_array(&n, &input[MAX_INPUT]);
    	printf("\n");
    	printf("Stage 1\n");
    	printf("=======\n");
    	printf("Number of sound inputs: %d\n", n);
    	print_array(input[MAX_INPUT]);
    	printf("\n");
    	
    return 0;
    }
    the program when run gives the following output:

    Ishtiaque-Mohammed-Khans-MacBook-Pro:Comp20005 IshtiaqueMKhan$ gcc -Wall -ansi -o ProjectB ProjectB.c
    ProjectB.c: In function ‘main’:
    ProjectB.c:59: error: incompatible type for argument 1 of ‘print_array’

    help? :/

  2. #2
    Join Date
    May 2012
    Posts
    3

    Re: help me find the error?

    print_array(input[MAX_INPUT]);


    just use:

    print_array(input);




    Quote Originally Posted by DaLastJudge View Post
    I am trying to read from a data file that has input as :

    12.0, 11, 123
    14.0, 12.1, 3


    and i want the program to read the data from the file and then make it into an array of structures and then print that array afterwards.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    	#define MAX_INPUT 1000
    
    int n =0;
    int i = 0;
    
    typedef struct
    {
    	double x[MAX_INPUT];
    	double y[MAX_INPUT];
    	double w[MAX_INPUT];
    }input_t;
    
    input_t input[MAX_INPUT];
    
    input_t
    read_int_array(int *n, input_t input[])
    {
    	int p=0;
    	int k=0;
    	double temp, temp3, temp2;
    	while (scanf("%lf %lf %lf", &temp, &temp2, &temp3)==3){
    		
    		input[k].x[k]=temp;
    		input[k].y[k]=temp2;
    		input[k].w[k]=temp3;
    		k++;
    		
    		p = *n;
    		p++;
    		*n = p;
    		
    	}
    	return input[MAX_INPUT];
    }
    
    void
    print_array(input_t input[])
    {	
    	int j=0;
    	for (j=0;j<n;j++)
    	{
    	printf("%.2lf meters east, ", input[j].x[j]);
    	printf("%.2lf meters north, ", input[j].y[j]);
    	printf("%.4lf Watts\n", input[j].w[j]);
    	}	
    }
    	
    int main(int argc, char **argv)
    {
    	input_t input[MAX_INPUT];
    	input[MAX_INPUT] = read_int_array(&n, &input[MAX_INPUT]);
    	printf("\n");
    	printf("Stage 1\n");
    	printf("=======\n");
    	printf("Number of sound inputs: %d\n", n);
    	print_array(input[MAX_INPUT]);
    	printf("\n");
    	
    return 0;
    }
    the program when run gives the following output:

    Ishtiaque-Mohammed-Khans-MacBook-Pro:Comp20005 IshtiaqueMKhan$ gcc -Wall -ansi -o ProjectB ProjectB.c
    ProjectB.c: In function ‘main’:
    ProjectB.c:59: error: incompatible type for argument 1 of ‘print_array’

    help? :/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured