Like Tree2Likes
  • 1 Post By anduril462
  • 1 Post By anduril462

Can't find compile error, anyone can help?

This is a discussion on Can't find compile error, anyone can help? within the C Programming forums, part of the General Programming Boards category; The error is highlighted with the red line. If anyone can help i would be very grateful. Compiler says expected ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    7

    Can't find compile error, anyone can help?

    The error is highlighted with the red line. If anyone can help i would be very grateful. Compiler says expected ';' ',' ', ' or ')' before numeric constant.

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<math.h>
    
    #define N 5 //countries
    #define M 13 //years
    
    //---To struct StatisticalData-----------------------------------------------------------//
    
     struct StatisticalData {
        char name[30];
        int num_years;
        int *years;
        float *inflation, *aep_growth, *investments;
        float avg_inflation, min_inflation, max_inflation;
        float avg_aep_growth, min_aep_growth, max_aep_growth;
        float avg_investments, min_investments, max_investments;
    };
    //--------------------------------------------------------------------------------------//
    //---H sunartisi LoadData---------------------------------------------------------------//
    int LoadData(struct StatisticalData *all_data)
    {
        FILE *infile1 =NULL;
        FILE *infile2 =NULL;
        FILE *infile3 =NULL;
        int i, j;
        float buf[100];
        char *c;
    
        infile1= fopen("inflation.ascii", "r");
        if(infile1==NULL)
        {
            printf("ERROR OPENING FILE inflation.ascii \n");
            exit(0);
        }
        for(i=0; i<N; i++)
        {
               fgets(buf, 99, infile1);
               c=strtok(buf, "\t");
               all_data[i].inflation[0]=atof(c);
               for(j=0; j<M; j++)
               {
                    c=strtok(NULL, "\t");
                    all_data[i].inflation[j]=atof(c);
               }
    
    
        }
    
        infile2= fopen("aep.ascii", "r");
        if(infile2==NULL)
        {
            printf("ERROR OPENING FILE aep.ascii \n");
            exit(0);
        }
        for(i=0; i<N; i++)
        {
               fgets(buf, 99, infile2);
               c=strtok(buf, "\t");
               all_data[i].aep_growth[0]=atof(c);
               for(j=0; j<M; j++)
               {
                    c=strtok(NULL, "\t");
                    all_data[i].aep_growth[j]=atof(c);
               }
    
    
        }
    
        infile3= fopen("investments.ascii", "r");
        if(infile3==NULL)
        {
            printf("ERROR OPENING FILE investments.ascii \n");
            exit(0);
        }
        for(i=0; i<N; i++)
        {
               fgets(buf, 99, infile3);
               c=strtok(buf, "\t");
               all_data[i].investments[0]=atof(c);
               for(j=0; j<M; j++)
               {
                    c=strtok(NULL, "\t");
                    all_data[i].investments[j]=atof(c);
               }
    
        }
    
        //--vazoume ta onomata twn xwrwn------------//
        strcpy(all_data[0].name,"Belgium");
        strcpy(all_data[1].name,"Chile");
        strcpy(all_data[2].name,"Greece");
        strcpy(all_data[3].name,"Japan");
        strcpy(all_data[4].name,"Zambia");
        //-----------------------------------------//
    
        //--vazoume tis xronologies----------------//
        for(i=0; i<N; i++)
        {
            all_data[i].years[0]=1990;
            all_data[i].years[1]=1991;
            all_data[i].years[2]=1992;
            all_data[i].years[3]=1993;
            all_data[i].years[4]=1994;
            all_data[i].years[5]=1995;
            all_data[i].years[6]=1996;
            all_data[i].years[7]=1997;
            all_data[i].years[8]=1998;
            all_data[i].years[9]=1999;
            all_data[i].years[10]=2000;
            all_data[i].years[11]=2001;
            all_data[i].years[12]=2002;
        }
        //---------------------------------------//
    
    
        return(0); //Epistrefei mhden epeidi ola pigan kala
    
    
    }
    //--telos tis sunartisis LoadData--------------------------------------------------------//
    
    //---H sunartisi calcStats---------------------------------------------------------------//
    
    void calcStats(struct StatisticalData *all_data)
    {
        int i,j;
        //---vriskoume tous mesous orous--------------------------------//
        for(i=0; i<N; i++)
        {
            all_data[i].avg_inflation=0;
            for(j=0; j<M; j++)
            {
                all_data[i].avg_inflation += all_data[i].inflation[j];
            }
            all_data[i].avg_inflation /= M;
        }
        for(i=0; i<N; i++)
        {
            all_data[i].avg_aep_growth=0;
            for(j=0; j<M; j++)
            {
                all_data[i].avg_aep_growth += all_data[i].aep_growth[j];
            }
            all_data[i].avg_aep_growth /= M;
        }
        for(i=0; i<N; i++)
        {
            all_data[i].avg_investments=0;
            for(j=0; j<M; j++)
            {
                all_data[i].avg_investments += all_data[i].investments[j];
            }
            all_data[i].avg_investments /= M;
        }
        //----------------------------------------------------------------------//
        //--vriskoume ta min kai max--------------------------------------------//
    
        for(i=0; i<N; i++)
        {
            all_data[i].min_inflation = all_data[i].inflation[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].inflation[j] < all_data[i].min_inflation)
                {
                    all_data[i].min_inflation = all_data[i].inflation[j];
                }
            }
    
        }
    
        for(i=0; i<N; i++)
        {
            all_data[i].min_aep_growth = all_data[i].aep_growth[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].aep_growth[j] < all_data[i].min_aep_growth)
                {
                    all_data[i].min_aep_growth = all_data[i].aep_growth[j];
                }
            }
    
        }
    
        for(i=0; i<N; i++)
        {
            all_data[i].min_investments = all_data[i].investments[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].investments[j] < all_data[i].min_investments)
                {
                    all_data[i].min_investments = all_data[i].investments[j];
                }
            }
    
        }
    
         for(i=0; i<N; i++)
        {
            all_data[i].max_inflation = all_data[i].inflation[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].inflation[j] > all_data[i].max_inflation)
                {
                    all_data[i].max_inflation = all_data[i].inflation[j];
                }
            }
    
        }
    
        for(i=0; i<N; i++)
        {
            all_data[i].max_aep_growth = all_data[i].aep_growth[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].aep_growth[j] > all_data[i].max_aep_growth)
                {
                    all_data[i].max_aep_growth = all_data[i].aep_growth[j];
                }
            }
    
        }
    
        for(i=0; i<N; i++)
        {
            all_data[i].max_investments = all_data[i].investments[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].investments[j] > all_data[i].max_investments)
                {
                    all_data[i].max_investments = all_data[i].investments[j];
                }
            }
    
        }
    
    }//--telos tis calcStats------------------------------------------------------------------//
    
    //--H sunartisi printXML------------------------------------------------------------------//
    
    void printXML(struct StatisticalData *all_data)
    {
        int i;
        FILE *outfile;
        outfile = fopen("summaryData.xml", "w");
        fprintf(outfile, "<stats>\n");
        for(i=0; i<N; i++)
        {
            fprintf(outfile, "\t <country> %s \n", all_data[i].name);
    
            fprintf(outfile, "\t\t <inflation>\n");
            fprintf(outfile, "\t\t\t <avg_inflation> %f </avg_inflation> \n", all_data[i].avg_inflation);
            fprintf(outfile, "\t\t\t <min_inflation> %f </min_inflation> \n", all_data[i].min_inflation);
            fprintf(outfile, "\t\t\t <max_inflation> %f </max_inflation> \n", all_data[i].max_inflation);
            fprintf(outfile, "\t\t </inflation>\n");
    
            fprintf(outfile, "\t\t <aep_growth>\n");
            fprintf(outfile, "\t\t\t <avg_aep_growth> %f </avg_aep_growth> \n", all_data[i].avg_aep_growth);
            fprintf(outfile, "\t\t\t <min_aep_growth> %f </min_aep_growth> \n", all_data[i].min_aep_growth);
            fprintf(outfile, "\t\t\t <max_aep_growth> %f </max_aep_growth> \n", all_data[i].max_aep_growth);
            fprintf(outfile, "\t\t </aep_growth>\n");
    
            fprintf(outfile, "\t\t <investments>\n");
            fprintf(outfile, "\t\t\t <avg_investments> %f </avg_investments> \n", all_data[i].avg_investments);
            fprintf(outfile, "\t\t\t <min_investments> %f </min_investments> \n", all_data[i].min_investments);
            fprintf(outfile, "\t\t\t <max_investments> %f </max_investments> \n", all_data[i].max_investments);
            fprintf(outfile, "\t\t </investments>\n");
    
            fprintf(outfile, "\t </country>\n");
        }
        fprintf(outfile, "</stats>\n");
    
    }//--telos tis printXML---------------------------------------------------------------//
    
    //--H voithitiki sunartisi findCountry-----------------------------------------------//
    
    int findCountry(struct StatisticalData *all_data, char *country)
    {
        int i;
        for(i=0; i<N; i++)
        {
            if(strcmp(country, all_data[i].name)==0)
            {
                return(i);
            }
            return(-1);
        }
    }//telos tis sunartisis findCountry-----------------------------------------------//
    
    //---H voithitiki sunartisi conv gia tin summetavlitotita-------------------------//
    
    int conv(float *posotita1, float *posotita2, float *avg_posotitas1, float *avg_posotitas2, float *convol, int N)
    {
        int i;
        *convol=0;
    
        for(i=0; i<N; i++)
        {
            *convol = posotita1[i]*posotita2[i]-avg_posotitas1*avg_posotitas2;
            *convol /= N;
        }
        if(*convol>0)
            return(1);
    
        else if(*convol<0)
            return(-1);
    
        else
            return(0);
    
    } //----------telos tis sunartisis conv---------------------------------------------------------
    
    //---Mia alli voithitiki gia tin summetavlitotita----------------------------------------------//
    
    void Help_Conv(float *inflation, float *aep_growth, float *investments, float *avg_inflation, float *avg_aep_growth, float *avg_investments, float *conv_inflationVSaep, float *conv_inflVSinvest, float *conv_aepVSinvest)
    {
        conv(inflation, aep_growth, avg_inflation, avg_aep_growth, conv_inflationVSaep, 13);
        conv(inflation, investments, avg_inflation, avg_investments, conv_inflVSinvest, 13);
        conv(aep_growth, investments, avg_aep_growth, avg_investments, conv_aepVSinvest, 13);
    
    }//--telos voithitikis------------------------------------------------------------------//
    
    //---H sunartisi All in One-------------------------------------------------------------//
    
    void AllinOne(struct StatisticalData *all_data, float *conv1, float *conv2, float *conv3)
    {
        int a;
        char country [10];
        printf("Dose onoma xwras gia anazitisi statistikwn stoixeiwn. \n");
        scanf("%s", country);
        a = findCountry(all_data, country);
        if(a!=-1)
        {
            Help_Conv(&all_data[a].inflation, &all_data[a].aep_growth, &all_data[a].investments, &all_data[a].avg_inflation, &all_data[a].avg_aep_growth, &all_data[a].avg_investments, conv1, conv2, conv3);
        }
        else
        {
            printf("H xwra den uparxei. \n");
        }
    }//--telos tis AllinOne------------------------------------------------------------------//
    
    
    //--------------------------------------------------------------------------------------//
    //                                      H main                                          //
    //--------------------------------------------------------------------------------------//
    main()
    {
        struct StatisticalData *all_data;
        int i, j, select;
        float conv1, conv2, conv3;
    
    
    
    //-------Kanoume malloc gia desmeusi tou all_data------------------------------------------//
        all_data=(struct StatisticalData*)malloc(N*sizeof(struct StatisticalData));
        if(all_data==NULL)
        {
            printf("Error allocating memory.\n");
            exit(0);
        }
        for(i=0; i<N; i++)
        {
            all_data[i].years=(int*)malloc(M*sizeof(int));
            all_data[i].inflation=(float*)malloc(M*sizeof(float));
            all_data[i].aep_growth=(float*)malloc(M*sizeof(float));
            all_data[i].investments=(float*)malloc(M*sizeof(float));
            if(all_data[i].years==NULL || all_data[i].inflation==NULL || all_data[i].aep_growth==NULL || all_data[i].investments==NULL)
            {
                printf("Error allocating memory.\n");
                exit(0);
            }
        }
    //-----------------------------------------------------------------------------------------//
    
        LoadData(all_data);
        calcStats(all_data);
        while(1)
        {
            printf("Menu epilogwn \n");
            printf("Dialekse ena apo ta parakatw: \n");
            printf("1. Ektypwsi meswn, megistwn kai elaxistwn timwn ana xwra.(se arxeio XML) \n");
            printf("2. Ypologismos summetavlitotitas. \n");
            printf("3. Exodos. \n");
            scanf("%d", select);
            switch(select)
            {
                case 1: printXML(all_data);
                    break;
                case 2: AllinOne(all_data, &conv1, &conv2, &conv3);
                    printf("H summetavlitotita metaksu inflation kai aep growth einai %f \n", conv1);
                    printf("H summetavlitotita metaksu inflation kai investments einai %f \n", conv2);
                    printf("H summetavlitotita metaksu aep growth kai investments einai %f \n", conv3);
                    break;
                case 3:
                    exit(0);
                default:
                    printf("Den uparxei tetoia epilogi. \n");
                    break;
    
            }
        }
    
    }//telos tis main

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,309
    There's a lot more problems than that. Always compile with your warnings turned all the way up, and fix them all (or as many as possible), and always start with the first one. Often, fixing the first error will "fix" other things the compiler complained about.
    Code:
    $ make bar
    gcc -Wall -g -std=c99  -lssl -lm -lpthread -lcurses -lefence  bar.c   -o bar
    bar.c: In function ‘LoadData’:
    bar.c:39: warning: passing argument 1 of ‘fgets’ from incompatible pointer type
    /usr/include/stdio.h:604: note: expected ‘char * restrict’ but argument is of type ‘float *’
    bar.c:40: warning: passing argument 1 of ‘strtok’ from incompatible pointer type
    /usr/include/string.h:346: note: expected ‘char * restrict’ but argument is of type ‘float *’
    bar.c:59: warning: passing argument 1 of ‘fgets’ from incompatible pointer type
    /usr/include/stdio.h:604: note: expected ‘char * restrict’ but argument is of type ‘float *’
    bar.c:60: warning: passing argument 1 of ‘strtok’ from incompatible pointer type
    /usr/include/string.h:346: note: expected ‘char * restrict’ but argument is of type ‘float *’
    bar.c:79: warning: passing argument 1 of ‘fgets’ from incompatible pointer type
    /usr/include/stdio.h:604: note: expected ‘char * restrict’ but argument is of type ‘float *’
    bar.c:80: warning: passing argument 1 of ‘strtok’ from incompatible pointer type
    /usr/include/string.h:346: note: expected ‘char * restrict’ but argument is of type ‘float *’
    bar.c: At top level:
    bar.c:293: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
    bar.c: In function ‘Help_Conv’:
    bar.c:318: warning: implicit declaration of function ‘conv’
    bar.c: In function ‘AllinOne’:
    bar.c:335: warning: passing argument 1 of ‘Help_Conv’ from incompatible pointer type
    bar.c:316: note: expected ‘float *’ but argument is of type ‘float **’
    bar.c:335: warning: passing argument 2 of ‘Help_Conv’ from incompatible pointer type
    bar.c:316: note: expected ‘float *’ but argument is of type ‘float **’
    bar.c:335: warning: passing argument 3 of ‘Help_Conv’ from incompatible pointer type
    bar.c:316: note: expected ‘float *’ but argument is of type ‘float **’
    bar.c: At top level:
    bar.c:348: warning: return type defaults to ‘int’
    bar.c: In function ‘main’:
    bar.c:385: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’
    bar.c:350: warning: unused variable ‘j’
    make: *** [bar] Error 1
    Most of that will go away with 3 simple fixes.

    • It appears you declared buf incorrectly on line 28.
    • You need to explicitly declare main to return an int. Try int main(void), and actually return an int at the end, usually 0.
    • On line 385, scanf expects the address of an integer, so use &select.


    As for the error you asked about, you #defined N to be 5. The preprocessor in C is just a fancy text replacement system. Everywhere you use N in your code, it gets replaced by the number 5 before your code is actually compiled. That means line 293 looks like the following to the compiler
    Code:
    int conv(float *posotita1, float *posotita2, float *avg_posotitas1, float *avg_posotitas2, float *convol, int 5)
    Which is not valid in a function declaration.
    Salem likes this.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    7
    ok thank's!!! I did the changes you said but i still get some errors about incompatible type for arguments
    here is the fixed code
    Code:
    // 
    
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<math.h>
    
    #define N 5 //countries
    #define M 13 //years
    
    //---To struct StatisticalData-----------------------------------------------------------//
    
     struct StatisticalData {
        char name[30];
        int num_years;
        int *years;
        float *inflation, *aep_growth, *investments;
        float avg_inflation, min_inflation, max_inflation;
        float avg_aep_growth, min_aep_growth, max_aep_growth;
        float avg_investments, min_investments, max_investments;
    };
    //--------------------------------------------------------------------------------------//
    //---H sunartisi LoadData---------------------------------------------------------------//
    int LoadData(struct StatisticalData *all_data)
    {
        FILE *infile1 =NULL;
        FILE *infile2 =NULL;
        FILE *infile3 =NULL;
        int i, j;
        char buf[100];
        char *c;
    
        infile1= fopen("inflation.ascii", "r");
        if(infile1==NULL)
        {
            printf("ERROR OPENING FILE inflation.ascii \n");
            exit(0);
        }
        for(i=0; i<N; i++)
        {
               fgets(buf, 99, infile1);
               c=strtok(buf, "\t");
               all_data[i].inflation[0]=atof(c);
               for(j=0; j<M; j++)
               {
                    c=strtok(NULL, "\t");
                    all_data[i].inflation[j]=atof(c);
               }
    
    
        }
    
        infile2= fopen("aep.ascii", "r");
        if(infile2==NULL)
        {
            printf("ERROR OPENING FILE aep.ascii \n");
            exit(0);
        }
        for(i=0; i<N; i++)
        {
               fgets(buf, 99, infile2);
               c=strtok(buf, "\t");
               all_data[i].aep_growth[0]=atof(c);
               for(j=0; j<M; j++)
               {
                    c=strtok(NULL, "\t");
                    all_data[i].aep_growth[j]=atof(c);
               }
    
    
        }
    
        infile3= fopen("investments.ascii", "r");
        if(infile3==NULL)
        {
            printf("ERROR OPENING FILE investments.ascii \n");
            exit(0);
        }
        for(i=0; i<N; i++)
        {
               fgets(buf, 99, infile3);
               c=strtok(buf, "\t");
               all_data[i].investments[0]=atof(c);
               for(j=0; j<M; j++)
               {
                    c=strtok(NULL, "\t");
                    all_data[i].investments[j]=atof(c);
               }
    
        }
    
        //--vazoume ta onomata twn xwrwn------------//
        strcpy(all_data[0].name,"Belgium");
        strcpy(all_data[1].name,"Chile");
        strcpy(all_data[2].name,"Greece");
        strcpy(all_data[3].name,"Japan");
        strcpy(all_data[4].name,"Zambia");
        //-----------------------------------------//
    
        //--vazoume tis xronologies----------------//
        for(i=0; i<N; i++)
        {
            all_data[i].years[0]=1990;
            all_data[i].years[1]=1991;
            all_data[i].years[2]=1992;
            all_data[i].years[3]=1993;
            all_data[i].years[4]=1994;
            all_data[i].years[5]=1995;
            all_data[i].years[6]=1996;
            all_data[i].years[7]=1997;
            all_data[i].years[8]=1998;
            all_data[i].years[9]=1999;
            all_data[i].years[10]=2000;
            all_data[i].years[11]=2001;
            all_data[i].years[12]=2002;
        }
        //---------------------------------------//
    
    
        return(0); //Epistrefei mhden epeidi ola pigan kala
    
    
    }
    //--telos tis sunartisis LoadData--------------------------------------------------------//
    
    //---H sunartisi calcStats---------------------------------------------------------------//
    
    void calcStats(struct StatisticalData *all_data)
    {
        int i,j;
        //---vriskoume tous mesous orous--------------------------------//
        for(i=0; i<N; i++)
        {
            all_data[i].avg_inflation=0;
            for(j=0; j<M; j++)
            {
                all_data[i].avg_inflation += all_data[i].inflation[j];
            }
            all_data[i].avg_inflation /= M;
        }
        for(i=0; i<N; i++)
        {
            all_data[i].avg_aep_growth=0;
            for(j=0; j<M; j++)
            {
                all_data[i].avg_aep_growth += all_data[i].aep_growth[j];
            }
            all_data[i].avg_aep_growth /= M;
        }
        for(i=0; i<N; i++)
        {
            all_data[i].avg_investments=0;
            for(j=0; j<M; j++)
            {
                all_data[i].avg_investments += all_data[i].investments[j];
            }
            all_data[i].avg_investments /= M;
        }
        //----------------------------------------------------------------------//
        //--vriskoume ta min kai max--------------------------------------------//
    
        for(i=0; i<N; i++)
        {
            all_data[i].min_inflation = all_data[i].inflation[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].inflation[j] < all_data[i].min_inflation)
                {
                    all_data[i].min_inflation = all_data[i].inflation[j];
                }
            }
    
        }
    
        for(i=0; i<N; i++)
        {
            all_data[i].min_aep_growth = all_data[i].aep_growth[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].aep_growth[j] < all_data[i].min_aep_growth)
                {
                    all_data[i].min_aep_growth = all_data[i].aep_growth[j];
                }
            }
    
        }
    
        for(i=0; i<N; i++)
        {
            all_data[i].min_investments = all_data[i].investments[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].investments[j] < all_data[i].min_investments)
                {
                    all_data[i].min_investments = all_data[i].investments[j];
                }
            }
    
        }
    
         for(i=0; i<N; i++)
        {
            all_data[i].max_inflation = all_data[i].inflation[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].inflation[j] > all_data[i].max_inflation)
                {
                    all_data[i].max_inflation = all_data[i].inflation[j];
                }
            }
    
        }
    
        for(i=0; i<N; i++)
        {
            all_data[i].max_aep_growth = all_data[i].aep_growth[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].aep_growth[j] > all_data[i].max_aep_growth)
                {
                    all_data[i].max_aep_growth = all_data[i].aep_growth[j];
                }
            }
    
        }
    
        for(i=0; i<N; i++)
        {
            all_data[i].max_investments = all_data[i].investments[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].investments[j] > all_data[i].max_investments)
                {
                    all_data[i].max_investments = all_data[i].investments[j];
                }
            }
    
        }
    
    }//--telos tis calcStats------------------------------------------------------------------//
    
    //--H sunartisi printXML------------------------------------------------------------------//
    
    void printXML(struct StatisticalData *all_data)
    {
        int i;
        FILE *outfile;
        outfile = fopen("summaryData.xml", "w");
        fprintf(outfile, "<stats>\n");
        for(i=0; i<N; i++)
        {
            fprintf(outfile, "\t <country> %s \n", all_data[i].name);
    
            fprintf(outfile, "\t\t <inflation>\n");
            fprintf(outfile, "\t\t\t <avg_inflation> %f </avg_inflation> \n", all_data[i].avg_inflation);
            fprintf(outfile, "\t\t\t <min_inflation> %f </min_inflation> \n", all_data[i].min_inflation);
            fprintf(outfile, "\t\t\t <max_inflation> %f </max_inflation> \n", all_data[i].max_inflation);
            fprintf(outfile, "\t\t </inflation>\n");
    
            fprintf(outfile, "\t\t <aep_growth>\n");
            fprintf(outfile, "\t\t\t <avg_aep_growth> %f </avg_aep_growth> \n", all_data[i].avg_aep_growth);
            fprintf(outfile, "\t\t\t <min_aep_growth> %f </min_aep_growth> \n", all_data[i].min_aep_growth);
            fprintf(outfile, "\t\t\t <max_aep_growth> %f </max_aep_growth> \n", all_data[i].max_aep_growth);
            fprintf(outfile, "\t\t </aep_growth>\n");
    
            fprintf(outfile, "\t\t <investments>\n");
            fprintf(outfile, "\t\t\t <avg_investments> %f </avg_investments> \n", all_data[i].avg_investments);
            fprintf(outfile, "\t\t\t <min_investments> %f </min_investments> \n", all_data[i].min_investments);
            fprintf(outfile, "\t\t\t <max_investments> %f </max_investments> \n", all_data[i].max_investments);
            fprintf(outfile, "\t\t </investments>\n");
    
            fprintf(outfile, "\t </country>\n");
        }
        fprintf(outfile, "</stats>\n");
    
    }//--telos tis printXML---------------------------------------------------------------//
    
    //--H voithitiki sunartisi findCountry-----------------------------------------------//
    
    int findCountry(struct StatisticalData *all_data, char *country)
    {
        int i;
        for(i=0; i<N; i++)
        {
            if(strcmp(country, all_data[i].name)==0)
            {
                return(i);
            }
            return(-1);
        }
    }//telos tis sunartisis findCountry-----------------------------------------------//
    
    //---H voithitiki sunartisi conv gia tin summetavlitotita-------------------------//
    
    int conv(float *posotita1, float *posotita2, float avg_posotitas1, float avg_posotitas2, float *convol)
    {
        int i;
        *convol=0;
    
        for(i=0; i<N; i++)
        {
            *convol = posotita1[i]*posotita2[i]-avg_posotitas1*avg_posotitas2;
            *convol /= N;
        }
        if(*convol>0)
            return(1);
    
        else if(*convol<0)
            return(-1);
    
        else
            return(0);
    
    } //----------telos tis sunartisis conv---------------------------------------------------------
    
    //---Mia alli voithitiki gia tin summetavlitotita----------------------------------------------//
    
    void Help_Conv(float *inflation, float *aep_growth, float *investments, float *avg_inflation, float *avg_aep_growth, float *avg_investments, float *conv_inflationVSaep, float *conv_inflVSinvest, float *conv_aepVSinvest)
    {
        conv(inflation, aep_growth, avg_inflation, avg_aep_growth, conv_inflationVSaep);
        conv(inflation, investments, avg_inflation, avg_investments, conv_inflVSinvest);
        conv(aep_growth, investments, avg_aep_growth, avg_investments, conv_aepVSinvest);
    
    }//--telos voithitikis------------------------------------------------------------------//
    
    //---H sunartisi All in One-------------------------------------------------------------//
    
    void AllinOne(struct StatisticalData *all_data, float *conv1, float *conv2, float *conv3)
    {
        int a;
        char country [10];
        printf("Dose onoma xwras gia anazitisi statistikwn stoixeiwn. \n");
        scanf("%s", country);
        a = findCountry(all_data, country);
        if(a!=-1)
        {
            Help_Conv(all_data[a].inflation, all_data[a].aep_growth, all_data[a].investments, all_data[a].avg_inflation, all_data[a].avg_aep_growth, all_data[a].avg_investments, conv1, conv2, conv3);
        }
        else
        {
            printf("H xwra den uparxei. \n");
        }
    }//--telos tis AllinOne------------------------------------------------------------------//
    
    
    //--------------------------------------------------------------------------------------//
    //                                      H main                                          //
    //--------------------------------------------------------------------------------------//
    int main()
    {
        struct StatisticalData *all_data;
        int i, j, select;
        float conv1, conv2, conv3;
    
    
    
    //-------Kanoume malloc gia desmeusi tou all_data------------------------------------------//
        all_data=(struct StatisticalData*)malloc(N*sizeof(struct StatisticalData));
        if(all_data==NULL)
        {
            printf("Error allocating memory.\n");
            exit(0);
        }
        for(i=0; i<N; i++)
        {
            all_data[i].years=(int*)malloc(M*sizeof(int));
            all_data[i].inflation=(float*)malloc(M*sizeof(float));
            all_data[i].aep_growth=(float*)malloc(M*sizeof(float));
            all_data[i].investments=(float*)malloc(M*sizeof(float));
            if(all_data[i].years==NULL || all_data[i].inflation==NULL || all_data[i].aep_growth==NULL || all_data[i].investments==NULL)
            {
                printf("Error allocating memory.\n");
                exit(0);
            }
        }
    //-----------------------------------------------------------------------------------------//
    
        LoadData(all_data);
        calcStats(all_data);
        while(1)
        {
            printf("Menu epilogwn \n");
            printf("Dialekse ena apo ta parakatw: \n");
            printf("1. Ektypwsi meswn, megistwn kai elaxistwn timwn ana xwra.(se arxeio XML) \n");
            printf("2. Ypologismos summetavlitotitas. \n");
            printf("3. Exodos. \n");
            scanf("%d", &select);
            switch(select)
            {
                case 1: printXML(all_data);
                    break;
                case 2: AllinOne(all_data, &conv1, &conv2, &conv3);
                    printf("H summetavlitotita metaksu inflation kai aep growth einai %f \n", conv1);
                    printf("H summetavlitotita metaksu inflation kai investments einai %f \n", conv2);
                    printf("H summetavlitotita metaksu aep growth kai investments einai %f \n", conv3);
                    break;
                case 3:
                    exit(0);
                default:
                    printf("Den uparxei tetoia epilogi. \n");
                    break;
    
            }
        }
    
    }//telos tis main

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,309
    In the future, always post the exact compiler error/warning messages with the line numbers. It often saves us the trouble of having to copy-paste and compile the code ourselves. Like so:
    Code:
    $ make bar
    gcc -Wall -g -std=c99  -lssl -lm -lpthread -lcurses -lefence  bar.c   -o bar
    bar.c: In function ‘Help_Conv’:
    bar.c:318: error: incompatible type for argument 3 of ‘conv’
    bar.c:293: note: expected ‘float’ but argument is of type ‘float *’
    bar.c:318: error: incompatible type for argument 4 of ‘conv’
    bar.c:293: note: expected ‘float’ but argument is of type ‘float *’
    bar.c:319: error: incompatible type for argument 3 of ‘conv’
    bar.c:293: note: expected ‘float’ but argument is of type ‘float *’
    bar.c:319: error: incompatible type for argument 4 of ‘conv’
    bar.c:293: note: expected ‘float’ but argument is of type ‘float *’
    bar.c:320: error: incompatible type for argument 3 of ‘conv’
    bar.c:293: note: expected ‘float’ but argument is of type ‘float *’
    bar.c:320: error: incompatible type for argument 4 of ‘conv’
    bar.c:293: note: expected ‘float’ but argument is of type ‘float *’
    bar.c: In function ‘AllinOne’:
    bar.c:335: error: incompatible type for argument 4 of ‘Help_Conv’
    bar.c:316: note: expected ‘float *’ but argument is of type ‘float’
    bar.c:335: error: incompatible type for argument 5 of ‘Help_Conv’
    bar.c:316: note: expected ‘float *’ but argument is of type ‘float’
    bar.c:335: error: incompatible type for argument 6 of ‘Help_Conv’
    bar.c:316: note: expected ‘float *’ but argument is of type ‘float’
    bar.c: In function ‘main’:
    bar.c:350: warning: unused variable ‘j’
    make: *** [bar] Error 1
    Those messages tell you exactly which parameters in which function calls are wrong. You need to decide, are you using float or pointer to float? I don't see any real need for pointer to float.
    Salem likes this.

  5. #5
    Registered User
    Join Date
    Dec 2010
    Posts
    7
    sorry for posting over and over the code but i use codeblocks compiler and it doesn't have an option to copy the errors, only the code.
    Now i corrected the errors in Help_Conv but i cannot correct the errors in AllinOne. Any idea what to do?
    Also new errors appeared in conv

    Code:
    // 
    
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<math.h>
    
    #define N 5 //countries
    #define M 13 //years
    
    //---To struct StatisticalData-----------------------------------------------------------//
    
     struct StatisticalData {
        char name[30];
        int num_years;
        int *years;
        float *inflation, *aep_growth, *investments;
        float avg_inflation, min_inflation, max_inflation;
        float avg_aep_growth, min_aep_growth, max_aep_growth;
        float avg_investments, min_investments, max_investments;
    };
    //--------------------------------------------------------------------------------------//
    //---H sunartisi LoadData---------------------------------------------------------------//
    int LoadData(struct StatisticalData *all_data)
    {
        FILE *infile1 =NULL;
        FILE *infile2 =NULL;
        FILE *infile3 =NULL;
        int i, j;
        char buf[100];
        char *c;
    
        infile1= fopen("inflation.ascii", "r");
        if(infile1==NULL)
        {
            printf("ERROR OPENING FILE inflation.ascii \n");
            exit(0);
        }
        for(i=0; i<N; i++)
        {
               fgets(buf, 99, infile1);
               c=strtok(buf, "\t");
               all_data[i].inflation[0]=atof(c);
               for(j=0; j<M; j++)
               {
                    c=strtok(NULL, "\t");
                    all_data[i].inflation[j]=atof(c);
               }
    
    
        }
    
        infile2= fopen("aep.ascii", "r");
        if(infile2==NULL)
        {
            printf("ERROR OPENING FILE aep.ascii \n");
            exit(0);
        }
        for(i=0; i<N; i++)
        {
               fgets(buf, 99, infile2);
               c=strtok(buf, "\t");
               all_data[i].aep_growth[0]=atof(c);
               for(j=0; j<M; j++)
               {
                    c=strtok(NULL, "\t");
                    all_data[i].aep_growth[j]=atof(c);
               }
    
    
        }
    
        infile3= fopen("investments.ascii", "r");
        if(infile3==NULL)
        {
            printf("ERROR OPENING FILE investments.ascii \n");
            exit(0);
        }
        for(i=0; i<N; i++)
        {
               fgets(buf, 99, infile3);
               c=strtok(buf, "\t");
               all_data[i].investments[0]=atof(c);
               for(j=0; j<M; j++)
               {
                    c=strtok(NULL, "\t");
                    all_data[i].investments[j]=atof(c);
               }
    
        }
    
        //--vazoume ta onomata twn xwrwn------------//
        strcpy(all_data[0].name,"Belgium");
        strcpy(all_data[1].name,"Chile");
        strcpy(all_data[2].name,"Greece");
        strcpy(all_data[3].name,"Japan");
        strcpy(all_data[4].name,"Zambia");
        //-----------------------------------------//
    
        //--vazoume tis xronologies----------------//
        for(i=0; i<N; i++)
        {
            all_data[i].years[0]=1990;
            all_data[i].years[1]=1991;
            all_data[i].years[2]=1992;
            all_data[i].years[3]=1993;
            all_data[i].years[4]=1994;
            all_data[i].years[5]=1995;
            all_data[i].years[6]=1996;
            all_data[i].years[7]=1997;
            all_data[i].years[8]=1998;
            all_data[i].years[9]=1999;
            all_data[i].years[10]=2000;
            all_data[i].years[11]=2001;
            all_data[i].years[12]=2002;
        }
        //---------------------------------------//
    
    
        return(0); //Epistrefei mhden epeidi ola pigan kala
    
    
    }
    //--telos tis sunartisis LoadData--------------------------------------------------------//
    
    //---H sunartisi calcStats---------------------------------------------------------------//
    
    void calcStats(struct StatisticalData *all_data)
    {
        int i,j;
        //---vriskoume tous mesous orous--------------------------------//
        for(i=0; i<N; i++)
        {
            all_data[i].avg_inflation=0;
            for(j=0; j<M; j++)
            {
                all_data[i].avg_inflation += all_data[i].inflation[j];
            }
            all_data[i].avg_inflation /= M;
        }
        for(i=0; i<N; i++)
        {
            all_data[i].avg_aep_growth=0;
            for(j=0; j<M; j++)
            {
                all_data[i].avg_aep_growth += all_data[i].aep_growth[j];
            }
            all_data[i].avg_aep_growth /= M;
        }
        for(i=0; i<N; i++)
        {
            all_data[i].avg_investments=0;
            for(j=0; j<M; j++)
            {
                all_data[i].avg_investments += all_data[i].investments[j];
            }
            all_data[i].avg_investments /= M;
        }
        //----------------------------------------------------------------------//
        //--vriskoume ta min kai max--------------------------------------------//
    
        for(i=0; i<N; i++)
        {
            all_data[i].min_inflation = all_data[i].inflation[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].inflation[j] < all_data[i].min_inflation)
                {
                    all_data[i].min_inflation = all_data[i].inflation[j];
                }
            }
    
        }
    
        for(i=0; i<N; i++)
        {
            all_data[i].min_aep_growth = all_data[i].aep_growth[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].aep_growth[j] < all_data[i].min_aep_growth)
                {
                    all_data[i].min_aep_growth = all_data[i].aep_growth[j];
                }
            }
    
        }
    
        for(i=0; i<N; i++)
        {
            all_data[i].min_investments = all_data[i].investments[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].investments[j] < all_data[i].min_investments)
                {
                    all_data[i].min_investments = all_data[i].investments[j];
                }
            }
    
        }
    
         for(i=0; i<N; i++)
        {
            all_data[i].max_inflation = all_data[i].inflation[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].inflation[j] > all_data[i].max_inflation)
                {
                    all_data[i].max_inflation = all_data[i].inflation[j];
                }
            }
    
        }
    
        for(i=0; i<N; i++)
        {
            all_data[i].max_aep_growth = all_data[i].aep_growth[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].aep_growth[j] > all_data[i].max_aep_growth)
                {
                    all_data[i].max_aep_growth = all_data[i].aep_growth[j];
                }
            }
    
        }
    
        for(i=0; i<N; i++)
        {
            all_data[i].max_investments = all_data[i].investments[0];
            for(j=0; j<M; j++)
            {
                if(all_data[i].investments[j] > all_data[i].max_investments)
                {
                    all_data[i].max_investments = all_data[i].investments[j];
                }
            }
    
        }
    
    }//--telos tis calcStats------------------------------------------------------------------//
    
    //--H sunartisi printXML------------------------------------------------------------------//
    
    void printXML(struct StatisticalData *all_data)
    {
        int i;
        FILE *outfile;
        outfile = fopen("summaryData.xml", "w");
        fprintf(outfile, "<stats>\n");
        for(i=0; i<N; i++)
        {
            fprintf(outfile, "\t <country> %s \n", all_data[i].name);
    
            fprintf(outfile, "\t\t <inflation>\n");
            fprintf(outfile, "\t\t\t <avg_inflation> %f </avg_inflation> \n", all_data[i].avg_inflation);
            fprintf(outfile, "\t\t\t <min_inflation> %f </min_inflation> \n", all_data[i].min_inflation);
            fprintf(outfile, "\t\t\t <max_inflation> %f </max_inflation> \n", all_data[i].max_inflation);
            fprintf(outfile, "\t\t </inflation>\n");
    
            fprintf(outfile, "\t\t <aep_growth>\n");
            fprintf(outfile, "\t\t\t <avg_aep_growth> %f </avg_aep_growth> \n", all_data[i].avg_aep_growth);
            fprintf(outfile, "\t\t\t <min_aep_growth> %f </min_aep_growth> \n", all_data[i].min_aep_growth);
            fprintf(outfile, "\t\t\t <max_aep_growth> %f </max_aep_growth> \n", all_data[i].max_aep_growth);
            fprintf(outfile, "\t\t </aep_growth>\n");
    
            fprintf(outfile, "\t\t <investments>\n");
            fprintf(outfile, "\t\t\t <avg_investments> %f </avg_investments> \n", all_data[i].avg_investments);
            fprintf(outfile, "\t\t\t <min_investments> %f </min_investments> \n", all_data[i].min_investments);
            fprintf(outfile, "\t\t\t <max_investments> %f </max_investments> \n", all_data[i].max_investments);
            fprintf(outfile, "\t\t </investments>\n");
    
            fprintf(outfile, "\t </country>\n");
        }
        fprintf(outfile, "</stats>\n");
    
    }//--telos tis printXML---------------------------------------------------------------//
    
    //--H voithitiki sunartisi findCountry-----------------------------------------------//
    
    int findCountry(struct StatisticalData *all_data, char *country)
    {
        int i;
        for(i=0; i<N; i++)
        {
            if(strcmp(country, all_data[i].name)==0)
            {
                return(i);
            }
            return(-1);
        }
    }//telos tis sunartisis findCountry-----------------------------------------------//
    
    //---H voithitiki sunartisi conv gia tin summetavlitotita-------------------------//
    
    int conv(float posotita1, float posotita2, float avg_posotitas1, float avg_posotitas2, float *convol)
    {
        int i;
        *convol=0;
    
        for(i=0; i<N; i++)
        {
            *convol = posotita1[i]*posotita2[i]-avg_posotitas1*avg_posotitas2;
            *convol /= N;
        }
        if(*convol>0)
            return(1);
    
        else if(*convol<0)
            return(-1);
    
        else
            return(0);
    
    } //----------telos tis sunartisis conv---------------------------------------------------------
    
    //---Mia alli voithitiki gia tin summetavlitotita----------------------------------------------//
    
    void Help_Conv(float inflation, float aep_growth, float investments, float avg_inflation, float avg_aep_growth, float avg_investments, float conv_inflationVSaep, float conv_inflVSinvest, float conv_aepVSinvest)
    {
        conv(inflation, aep_growth, avg_inflation, avg_aep_growth, &conv_inflationVSaep);
        conv(inflation, investments, avg_inflation, avg_investments, &conv_inflVSinvest);
        conv(aep_growth, investments, avg_aep_growth, avg_investments, &conv_aepVSinvest);
    
    }//--telos voithitikis------------------------------------------------------------------//
    
    //---H sunartisi All in One-------------------------------------------------------------//
    
    void AllinOne(struct StatisticalData *all_data, float *conv1, float *conv2, float *conv3)
    {
        int a;
        char country [10];
        printf("Dose onoma xwras gia anazitisi statistikwn stoixeiwn. \n");
        scanf("%s", country);
        a = findCountry(all_data, country);
        if(a!=-1)
        {
            Help_Conv(all_data[a].inflation, all_data[a].aep_growth, all_data[a].investments, all_data[a].avg_inflation, all_data[a].avg_aep_growth, all_data[a].avg_investments, conv1, conv2, conv3);
        }
        else
        {
            printf("H xwra den uparxei. \n");
        }
    }//--telos tis AllinOne------------------------------------------------------------------//
    
    
    //--------------------------------------------------------------------------------------//
    //                                      H main                                          //
    //--------------------------------------------------------------------------------------//
    int main()
    {
        struct StatisticalData *all_data;
        int i, j, select;
        float conv1, conv2, conv3;
    
    
    
    //-------Kanoume malloc gia desmeusi tou all_data------------------------------------------//
        all_data=(struct StatisticalData*)malloc(N*sizeof(struct StatisticalData));
        if(all_data==NULL)
        {
            printf("Error allocating memory.\n");
            exit(0);
        }
        for(i=0; i<N; i++)
        {
            all_data[i].years=(int*)malloc(M*sizeof(int));
            all_data[i].inflation=(float*)malloc(M*sizeof(float));
            all_data[i].aep_growth=(float*)malloc(M*sizeof(float));
            all_data[i].investments=(float*)malloc(M*sizeof(float));
            if(all_data[i].years==NULL || all_data[i].inflation==NULL || all_data[i].aep_growth==NULL || all_data[i].investments==NULL)
            {
                printf("Error allocating memory.\n");
                exit(0);
            }
        }
    //-----------------------------------------------------------------------------------------//
    
        LoadData(all_data);
        calcStats(all_data);
        while(1)
        {
            printf("Menu epilogwn \n");
            printf("Dialekse ena apo ta parakatw: \n");
            printf("1. Ektypwsi meswn, megistwn kai elaxistwn timwn ana xwra.(se arxeio XML) \n");
            printf("2. Ypologismos summetavlitotitas. \n");
            printf("3. Exodos. \n");
            scanf("%d", &select);
            switch(select)
            {
                case 1: printXML(all_data);
                    break;
                case 2: AllinOne(all_data, &conv1, &conv2, &conv3);
                    printf("H summetavlitotita metaksu inflation kai aep growth einai %f \n", conv1);
                    printf("H summetavlitotita metaksu inflation kai investments einai %f \n", conv2);
                    printf("H summetavlitotita metaksu aep growth kai investments einai %f \n", conv3);
                    break;
                case 3:
                    exit(0);
                default:
                    printf("Den uparxei tetoia epilogi. \n");
                    break;
    
            }
        }
    
    }//telos tis main

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,309
    EDIT: Code::Blocks (which is an IDE, not a compiler) does have a way to copy that information, many others on this site have managed to do it. Unfortunately, I don't use C::B so at best, I would guess that the errors show up in a separate window on the bottom. Perhaps you can select lines in there and copy them to the clipboard somehow. Try scrolling up in that window if they have disappeared from the screen.

    It's basically the same error as before. You must make sure the types match. If the function you are calling expects a float, pass it a float. If it expects a pointer to float, pass it a pointer to float.

    Look at AllinOne. conv1, conv2 and conv3 are parameters that are all pointers to float. They are passed as the last 3 parameters to Help_Conv.

    Now look at Help_Conv. It's last 3 parameters are floats, not pointers to float. Each one is passed as the last param to conv, which expects a pointer to float. You pass &conv_inflationVSaep, et al. That & gives you the address of the local copy of conv_inflationVSaep, it's not the same address of conv1, conv2 or conv3 in AllinOne or main. The changes wont propagate back up to AllinOne and main.

    It looks like conv wants to change the value of convol, so it must be pointer to float. That also means the last 3 parameters to Help_Conv should be pointer to float. Then, you just pass them along to conv, no need for a &.

  7. #7
    Registered User
    Join Date
    Dec 2010
    Posts
    7
    I still cannot fix it, and i am very tired to try it more right now but anyway thank's for your help!! :-)

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,341
    Name:  Screenshot-main.cpp [simple] - Code::Blocks 10.05.png
Views: 392
Size:  86.1 KB
    Copying error messages is as simple as falling off a log (file)
    Just right-click on the build messages tab.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. System can not find file after compile/linking...
    By evb@studioe.com in forum C Programming
    Replies: 8
    Last Post: 02-15-2012, 05:21 PM
  2. Replies: 15
    Last Post: 11-28-2011, 10:48 AM
  3. Replies: 2
    Last Post: 11-22-2010, 05:32 PM
  4. Replies: 7
    Last Post: 03-19-2010, 12:16 AM
  5. compile time error or runtime error?
    By George2 in forum C# Programming
    Replies: 3
    Last Post: 05-07-2008, 07:08 AM

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