Thread: Compiling errors...(30 lines of code)

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    158

    Compiling errors...(30 lines of code)

    Code:
    #include <stdio.h>
    #define MAX_ARRAY_SIZE 20
    int get_corners(FILE* fp,double x_array[],double y_array[],MAX_ARRAY_SIZE);
      
     void output_corners(FILE* foutput,double x_array[],double y_array[],int *actual_size);
      
     double polygon_area(double x_array[],double y_array[],int*actual_size);
       
       int main(int argc,char*argv[])
      {
      int actual_size;
      double x_array[MAX_ARRAY_SIZE];
      double y_array[MAX_ARRAY_SIZE];
      int i=0;
      int j=0;
      
      FILE *fp;                                                                           //opens a file and reads it. Then calls get_corners function which then extracts data from it
       fp =fopen(argv[1],"r");
      get_corners(&fp,x_array,y_array,MAX_ARRAY_SIZE);
      
      FILE *foutput;                                                                   //opens a file and writes to it. Using output parameters
      foutput=fopen(argv[2],"w");
      output_corners(&foutput,x_array,y_array,&actual_size);
      
      polygon_area(x_array,y_array,&actual_size);                      //calculates polygon area
      return 0;
      }//main
      
      
      int get_corners(FILE *fp,double x_array[],double y_array[],MAX_ARRAY_SIZE)
      {
      FILE *fp;
      fp =fopen(argv[1],"r");
      while(fscanf(fp,"%lf%lf",&x_array[i],&y_array[j])!=EOF)
      {
      i++;
      j++;
      }
      return *actual_size=j;
      
      }
      
      void output_corners(FILE*foutput,double x_array[],double y_array[],int *actual_size)
      {
      
      
      }
      double polygon_area(double x_array[],double y_array[],int *actual_size)
      {
      
      return 0;
    gcc -Wall polygon.c
    polygon.c:5:60: error: expected declaration specifiers or '...' before numeric constant

    polygon.c: In function 'main':
    polygon.c:19:1: warning: implicit declaration of function 'get_corners' [-Wimplicit-function-declaration]
    polygon.c:23:1: warning: passing argument 1 of 'output_corners' from incompatible pointer type [enabled by default]
    polygon.c:6:6: note: expected 'struct FILE *' but argument is of type 'struct FILE **'

    polygon.c: At top level:
    polygon.c:30:60: error: expected declaration specifiers or '...' before numeric constant

    Can someone tell me why my macro MAX_ARRAY_SIZE is showing up as an error? (Line 5)

    Also whats wrong with Lines 6,19,23?

    Thanks so much guys
    Last edited by tmac619619; 11-05-2012 at 11:47 PM.

  2. #2
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    Code:
    get_corners(&fp,x_array,y_array,MAX_ARRAY_SIZE);
    should be
    Code:
    get_corners(fp,x_array,y_array,MAX_ARRAY_SIZE);
    Thats one thing and look at this
    Code:
    int get_corners(FILE* fp,double x_array[],double y_array[],MAX_ARRAY_SIZE);
    I dont think you mean to put MAX_ARRAY_SIZE in that spot.

    Remember that MAX_ARRAY_SIZE is a constant, meaning you do not have to pass it in to your functions.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors when compiling code.
    By mvelez83 in forum C Programming
    Replies: 5
    Last Post: 02-06-2012, 01:52 PM
  2. Errors after compiling
    By CroBoss in forum C++ Programming
    Replies: 3
    Last Post: 06-09-2010, 10:21 AM
  3. Please help, 4 lines of errors i just cant solve!!!
    By AShaw in forum C Programming
    Replies: 1
    Last Post: 07-22-2009, 05:20 AM
  4. errors when compiling, but I don't know what they mean
    By indigo0086 in forum C++ Programming
    Replies: 7
    Last Post: 11-04-2002, 02:50 PM
  5. I get errors, but not from compiling
    By Leeman_s in forum C++ Programming
    Replies: 1
    Last Post: 01-20-2002, 02:07 PM