Thread: Malloc and floating point illegal use error

  1. #1
    Registered User
    Join Date
    Sep 2016
    Posts
    2

    Malloc and floating point illegal use error

    Hi all,

    I am getting a lot of errors with my C - code, with regards to malloc and illegal use of floating point.

    My code is as follows:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #define PI 3.14159265358
    
    
    // Define functions
    void calculate_impedance(double* result_table[6], int components_type[], double component_value[], int component_number, int source_voltage, int frequency, int circuit_type);
    void print_results(double* result_table[6], int component_number, int component_type[]); // Function to print result
    
    
    int i;
    double temp_impedRR, temp_impedCR, temp_impedlR, temp_impedReal, temp_impedImag, temp_impedRI, temp_impedCI, temp_impedlI; // impedance variables
    double voltreal_R, voltimag_R, voltreal_C, voltimag_C, voltreal_L, voltimag_L, total_voltReal, total_voltImag; // voltage variables (real voltage, imaginary voltage and total voltage - for each item R = resistor, C - capacitor and i - inductor)
    double curreal_R, curimag_R, curreal_C, curimag_C, curreal_L, curimag_L, total_curReal, total_curImag; // Current variables (real current, imaginary current and total current)
    int main()
    {
    
    
        //Define variables
        int parallel;
        int series;
        int frequency;
        int source_voltage;
        int component_number;
        int circuit_type; 
        float Zr;
        float Zc;
        float Zl;
        double Zrc_real;
        double Zrc_imag;
        double current_real;
        double current_imag;
        double Vr, Vc, Vl;
        double Ir;
        double Ic_real;
        double Ic_imag;
        double Il_real;
        double Il_imag;
        int i;
        double* result_table[6];
        
        
        
        
    
    
        
        // Printf statements to get the user input
        printf("**17763564 Ananth Kadekodi Assignment 2**\n");
        
        printf("Do you want to create a 1.Parallel or 2.Series circuit evaluation?\n");
        scanf("%d", &circuit_type);
        
        printf("Enter the frequency in Hertz of the source: \n");
        scanf("%d", &frequency);
        
        printf("Enter the source source_voltage: \n");
        scanf("%d", &source_voltage);
            
        printf("How many components are present \n"); // number of components
        scanf("%d", &component_number);
        
        
        //for loop to allcate malloc memory
        for(i=0; i < 6; i++)
        {
            result_table[i] = malloc((component_number+1)*sizeof(double)); //allocate malloc memory for 3D array
                
        }
        
        result_table[4][component_number] = source_voltage;
        result_table[5][component_number] = 0;
            
        // allocating memory for component_type and component_values
        int* component_type = malloc((component_number)*sizeof(int));
        double* component_value = malloc((component_number)*sizeof(double));
        int* type_ptrPosition = component_type; // pointer calculation done
        double* value_ptrPosition = component_value;// pointer calculation done
        
        
    
    
        switch(circuit_type) // Switch - Case statements for user input
        {
    
    
            case 1: 
            
                // For- loop for the component_number
                for (i = 0; i < component_number; i++)
                {
                    printf("Enter the component type for each component where 1 is resistor, 2 is capacitor and 3 is inductor\n");
                    scanf("%d", &type_ptrPosition);
                    
                    
                    if (component_type[i] == 1)
                    {
                        printf("Component %d: \n", (i+1));
                        printf("Enter the component_value of the component in Ohms: \n");
                        scanf("%lf", &value_ptrPosition);
                        
                    } else if (component_type[i]== 2)
                    {
                        printf("Component %d: \n", (i+1));
                        printf("Enter the component_value of the component in Farads: \n");
                        scanf("%lf", &value_ptrPosition);
                    
                    } else if (component_type[i] == 3)
                    {
                        printf("Component %d: \n", (i+1));
                        printf("Enter the component_value of the component_number in Henrys: \n");
                        scanf("%lf", &value_ptrPosition);
                        
                    }
                    
                    calculate_impedance(&result_table[6], component_type, component_value, component_number, frequency, circuit_type, source_voltage);
                    print_results(&result_table[6], component_number, component_type);
                    
                    
                    type_ptrPosition++;
                    value_ptrPosition++;    
                }
                
                break;
                
            case 2:
                
            
                
                for (i = 0; i < component_number; i++)
                {
                    printf("Enter the component type for each component where 1 is resistor, 2 is capacitor and 3 is inductor\n");
                    scanf("%d", &type_ptrPosition);
                    
                        
                    if (component_type[i] == 1)
                    {
                        printf("Component %d: \n", (i+1));
                        printf("Enter the component_value of the component in Ohms: \n");
                        scanf("%lf", &value_ptrPosition);
                        
                    } else if (component_type[i] == 2)
                    {
                        printf("Component %d: \n", (i+1));
                        printf("Enter the component_value of the component in Farads: \n");
                        scanf("%lf", &value_ptrPosition);
                    
                    } else if (component_type[i] == 3)
                    {
                        printf("Component %d: \n", (i+1));
                        printf("Enter the component_value of the component_number in Henrys: \n");
                        scanf("%lf", &value_ptrPosition);
                        
                    }
                    
                    calculate_impedance(&result_table[6], component_type, component_value, component_number, frequency, circuit_type, source_voltage);
                    print_results(&result_table[6], component_number, component_type);
                    
                    type_ptrPosition++;
                    value_ptrPosition++;
                }
                
                
                break;
                
            default:
                
                printf("You have specified an invalid input\n");
                printf("\n \n");
        }
        
        return 0;
        
    }
    
    
    // Calculation impedance function
    void calculate_impedance(double *result_table[6], int component_type[], double component_value[], int component_number, int frequency, int circuit_type, int source_voltage)
    {
        //define variables
    
    
        
        // CR = Capacitance real, voltimag_C (imaginary value of voltage capacitance), curreal_R - real value of current resistor, total_curReal - total real current values
    
    
        
        if(circuit_type == 1)
        {
            for (i=0; i< component_number; i++)
            {
                if(component_type[i] == 1)
                {
                    // calculations
                    temp_impedRR = component_value; // Impedance real part of resistor
                    temp_impedRI = 0;
                    voltreal_R = source_voltage;
                    voltimag_R = 0;
                    curreal_R = (source_voltage/component_value);
                    curimag_R = 0;
                    *result_table[0][i] = temp_impedRR; // Store values in array
                    *result_table[1][i] = temp_impedRI;
                    *result_table[4][i] = voltreal_R;
                    *result_table[5][i] = voltimag_R;
                    *result_table[2][i] = curreal_R;
                    *result_table[3][i] = curimag_R;
                    
                }else if (component_type[i] == 2)
                {
                    temp_impedCI = (double)(0-(1/(2*PI*frequency*component_value)));
                    temp_impedCR = 0;
                    voltreal_C = source_voltage; // voltage real value of capacitor
                    voltimag_C = 0;
                    curreal_C = ((source_voltage*0)+(0*temp_impedCI))/((0*0)+(temp_impedCI*temp_impedCI)); // current real value of capacitor
                    curimag_C = ((0*0)-(source_voltage*temp_impedCI))/((0*0)+(temp_impedCI*temp_impedCI)); // current imaginary value of capacitor
                    *result_table[0][i] = temp_impedRR; // store values in array
                    *result_table[1][i] = temp_impedRI;
                    *result_table[4][i] = voltreal_C;
                    *result_table[5][i] = voltimag_C;
                    *result_table[3][i] = curreal_C;
                    *result_table[4][i] = curimag_C;
                
            }else if (component_type[i] == 3)
            {
                temp_impedlR = 0;
                temp_impedlI = (2*PI*frequency*component_value);
                voltreal_L = source_voltage;
                voltimag_L = 0;
                curreal_L = ((source_voltage*0)+(0*temp_impedlI))/((0*0)+(temp_impedlI*temp_impedlI));
                curimag_L = ((0*0)-(source_voltage*temp_impedlI))/((0*0)+(temp_impedlI*temp_impedlI));
            
                *result_table[0][i] = temp_impedlR;
                *result_table[1][i]    = temp_impedlI;        
                *result_table[4][i] = voltreal_L;
                *result_table[5][i] = voltimag_L;
                *result_table[3][i] = curreal_L;
                *result_table[3][i] = curimag_L;
                    
            }
                    
                temp_impedReal = (((temp_impedRR*0)+(0*temp_impedlI))/((0*0)+(temp_impedlI*temp_impedlI))); // Temporary impedance real value
                
                temp_impedImag = ((temp_impedRR*0)-(temp_impedRR*temp_impedlI))/((0*0)+(temp_impedlI*temp_impedlI)); // Temporary impedance imaginary
            
                imped_real = ((temp_impedReal*0)+(temp_impedImag*temp_impedlI))/((0*0)+(temp_impedlI*temp_impedlI)); // Total impedance real
                *result_table[0][component_number] = imped_real; // store in Array
                imped_imag = ((temp_impedImag*0)-(temp_impedReal*temp_impedlI))/((0*0)+(temp_impedlI*temp_impedlI)); // Total impedance imaginary
                *result_table[1][component_number] = imped_imag; // store in array
                
                
                total_curReal = (((source_voltage*imped_real)+(0*imped_imag))/((imped_real*imped_real)+(imped_imag*imped_imag))); // Total current real
                *result_table[2][component_number] = total_curReal;
            
                total_curImag = ((0*imped_real)-(source_voltage*imped_imag))/((imped_real*imped_real)+(imped_imag*imped_imag)); // Total current imaginary
                *result_table[3][component_number] = total_curReal;
                
            }
            
        }    
        else if (circuit_type == 2)
        {
            for (i=0; i< component_number; i++)
            {
                
                if(component_type[i] == 1)
                {
                    temp_impedRR = component_value; // Temp total impedance of Resistor Real
                    temp_impedRI = 0; // Temp total impedance of Resistor Imaginary
    
    
                }else if (component_type[i] == 2)
                {
                    temp_impedCR = 0-(1/(2*PI*frequency*component_value));
                    temp_impedCI = 0;
                    
                }else if(component_type[i] == 3)
                {
                    temp_impedlR = (2*PI*frequency*component_value);  // Temp total impedance of inductor Real
                    temp_impedlI = 0; // Temp total impedance of inductor imaginary
                    
                }
                
                temp_impedReal = (temp_impedRR + 0);
                temp_impedImag = (0 + temp_impedCR);
                imped_real = (temp_impedRReal + 0);
                *result_table[0][component_number] = imped_real;
                imped_imag = (temp_impedImag + temp_impedlR);
                *result_table[1][component_number] = imped_imag;
                
                total_curReal = ((source_voltage*imped_real)+(0*imped_imag)/((imped_real*imped_real)+(imped_imag*imped_imag));
                *result_table[2][component_number] = total_curReal;
                *result_table[2][i] = total_curReal;
            
                total_curImag = ((0*out3_real)-(source_voltage*imped_imag))/((imped_real*imped_real)+(imped_imag*imped_imag));
                *result_table[3][component_number] = total_curImag;
                *result_table[3][i] = total_curImag;
            
                if(component_type[i] == 1)
                {
                    voltreal_R = ((temp_impedRR*total_curReal)-(temp_impedRI*total_curImag));
                    voltimag_R = ((temp_impedRI*tatal_curReal)+(temp_impedRR*total_curImag));
                    *result_table[4][i] = voltreal_R;
                    *result_table[5][i] = voltimag_R;
                    
                }else if(component_type[i] == 2)
                {
                    voltreal_C = ((temp_impedCR*total_curReal)-(temp_impedCI*total_curImag));
                    voltimag_C = ((temp_impedCI*tatal_curReal)+(temp_impedCR*total_curImag));
                    *result_table[4][i] = voltreal_C;
                    *result_table[5][i] = voltimag_C;
                    
                }else if(component_type[i] == 3)
                {
                    voltreal_L = ((temp_impedlR*total_curReal)-(temp_impedlI*total_curImag)); // Total voltage real value of inductor
                    voltimag_L = ((temp_impedRlI*tatal_curReal)+(temp_impedlR*total_curImag));    // Total voltage imaginary value of inductor
                    *result_table[4][i] = voltreal_L;
                    *result_table[5][i] = voltimag_L;
                }
            }
                
        }
    
    
        
    void print_results(double *result_table[6], int component_number, int component_type) // Function to print result
        {
            //Declare variable
            int i,j;
            
            // Print results
            printf("COMPONENTS ");
            printf("           |              R             ");
            
            printf("                                        |              C             ");
            printf("                                                                                    I             |");
            printf("                                                                                                              Total        |\n");
            printf("Z ( Ohms ) |"); 
            for(i=0; i < 1; i++)
            {
                for (j=0; j <= 6; j++ ) // For loop to print out array row 0 and 1
                {
                     printf("| %lf% |", &result_table[0][j]);
                     printf("%lf%", &result_table[1][j]);
                }    
            }
            printf("\n");
            printf("I ( Amps ) |");
            for(i=0; i < 1; i++) // For loop to print out array 2 and 3
            {
                for (j=0; j <= 6; j++ )
                {
                     printf("| %lf% |", &result_table[2][j]);
                     printf("%lf%", &result_table[3][j]);
                }    
            }
            printf("\n");
            printf("V ( Volts) |");
            for(i=0; i < 1; i++) // For loop to print out array 4 and 5
            {
                for (j=0; j <= 6; j++ )
                {
                     printf("| %lf% |", &result_table[4][j]);
                     printf("%lf%", &result_table[5][j]);
                }    
            }
        
        }        
    }
    Errors I am getting from Borland:

    Error E2140 codeeditedp1.c 72: Declaration is not allowed here in function main
    Error E2140 codeeditedp1.c 73: Declaration is not allowed here in function main
    Error E2140 codeeditedp1.c 74: Declaration is not allowed here in function main
    Error E2140 codeeditedp1.c 75: Declaration is not allowed here in function main
    Error E2060 codeeditedp1.c 187: Illegal use of floating point in function calculate_impedance
    Error E2087 codeeditedp1.c 191: Illegal use of pointer in function calculate_impedance
    Error E2060 codeeditedp1.c 193: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 194: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 195: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 196: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 197: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 198: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 202: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 208: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 209: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 210: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 211: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 212: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 213: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 218: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 224: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 225: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 226: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 227: Illegal use of floating point in function calculate_impedance
    Error E2060 codeeditedp1.c 228: Illegal use of floating point in function calculate_impedance
    Error E2228 codeeditedp1.c 228: Too many error or warning messages in function calculate_impedance




    Any suggestions would be appreciated!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    My first suggestion is don't write 400 lines of code without compiling it. You just end up with a disheartening long list of messages to deal with.

    The first big thing to do is remove the leading * from all the lines which look like this
    *result_table[0][i] = temp_impedRR;
    to read
    result_table[0][i] = temp_impedRR;


    Borland is letting you off lightly, GCC has far more to say.
    Code:
    $ gcc -Wall main.c
    main.c: In function ‘main’:
    main.c:94:23: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int **’ [-Wformat=]
                     scanf("%d", &type_ptrPosition);
                           ^
    main.c:101:27: warning: format ‘%lf’ expects argument of type ‘double *’, but argument 2 has type ‘double **’ [-Wformat=]
                         scanf("%lf", &value_ptrPosition);
                               ^
    main.c:107:27: warning: format ‘%lf’ expects argument of type ‘double *’, but argument 2 has type ‘double **’ [-Wformat=]
                         scanf("%lf", &value_ptrPosition);
                               ^
    main.c:113:27: warning: format ‘%lf’ expects argument of type ‘double *’, but argument 2 has type ‘double **’ [-Wformat=]
                         scanf("%lf", &value_ptrPosition);
                               ^
    main.c:134:23: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int **’ [-Wformat=]
                     scanf("%d", &type_ptrPosition);
                           ^
    main.c:141:27: warning: format ‘%lf’ expects argument of type ‘double *’, but argument 2 has type ‘double **’ [-Wformat=]
                         scanf("%lf", &value_ptrPosition);
                               ^
    main.c:147:27: warning: format ‘%lf’ expects argument of type ‘double *’, but argument 2 has type ‘double **’ [-Wformat=]
                         scanf("%lf", &value_ptrPosition);
                               ^
    main.c:153:27: warning: format ‘%lf’ expects argument of type ‘double *’, but argument 2 has type ‘double **’ [-Wformat=]
                         scanf("%lf", &value_ptrPosition);
                               ^
    main.c:39:12: warning: unused variable ‘Il_imag’ [-Wunused-variable]
         double Il_imag;
                ^
    main.c:38:12: warning: unused variable ‘Il_real’ [-Wunused-variable]
         double Il_real;
                ^
    main.c:37:12: warning: unused variable ‘Ic_imag’ [-Wunused-variable]
         double Ic_imag;
                ^
    main.c:36:12: warning: unused variable ‘Ic_real’ [-Wunused-variable]
         double Ic_real;
                ^
    main.c:35:12: warning: unused variable ‘Ir’ [-Wunused-variable]
         double Ir;
                ^
    main.c:34:20: warning: unused variable ‘Vl’ [-Wunused-variable]
         double Vr, Vc, Vl;
                        ^
    main.c:34:16: warning: unused variable ‘Vc’ [-Wunused-variable]
         double Vr, Vc, Vl;
                    ^
    main.c:34:12: warning: unused variable ‘Vr’ [-Wunused-variable]
         double Vr, Vc, Vl;
                ^
    main.c:33:12: warning: unused variable ‘current_imag’ [-Wunused-variable]
         double current_imag;
                ^
    main.c:32:12: warning: unused variable ‘current_real’ [-Wunused-variable]
         double current_real;
                ^
    main.c:31:12: warning: unused variable ‘Zrc_imag’ [-Wunused-variable]
         double Zrc_imag;
                ^
    main.c:30:12: warning: unused variable ‘Zrc_real’ [-Wunused-variable]
         double Zrc_real;
                ^
    main.c:29:11: warning: unused variable ‘Zl’ [-Wunused-variable]
         float Zl;
               ^
    main.c:28:11: warning: unused variable ‘Zc’ [-Wunused-variable]
         float Zc;
               ^
    main.c:27:11: warning: unused variable ‘Zr’ [-Wunused-variable]
         float Zr;
               ^
    main.c:22:9: warning: unused variable ‘series’ [-Wunused-variable]
         int series;
             ^
    main.c:21:9: warning: unused variable ‘parallel’ [-Wunused-variable]
         int parallel;
             ^
    main.c: In function ‘calculate_impedance’:
    main.c:196:30: error: incompatible types when assigning to type ‘double’ from type ‘double *’
                     temp_impedRR = component_value; // Impedance real part of resistor
                                  ^
    main.c:200:44: error: invalid operands to binary / (have ‘int’ and ‘double *’)
                     curreal_R = (source_voltage/component_value);
                                                ^
    main.c:202:17: error: invalid type argument of unary ‘*’ (have ‘double’)
                     *result_table[0][i] = temp_impedRR; // Store values in array
                     ^
    main.c:203:17: error: invalid type argument of unary ‘*’ (have ‘double’)
                     *result_table[1][i] = temp_impedRI;
                     ^
    main.c:204:17: error: invalid type argument of unary ‘*’ (have ‘double’)
                     *result_table[4][i] = voltreal_R;
                     ^
    main.c:205:17: error: invalid type argument of unary ‘*’ (have ‘double’)
                     *result_table[5][i] = voltimag_R;
                     ^
    main.c:206:17: error: invalid type argument of unary ‘*’ (have ‘double’)
                     *result_table[2][i] = curreal_R;
                     ^
    main.c:207:17: error: invalid type argument of unary ‘*’ (have ‘double’)
                     *result_table[3][i] = curimag_R;
                     ^
    main.c:211:61: error: invalid operands to binary * (have ‘double’ and ‘double *’)
                     temp_impedCI = (double)(0-(1/(2*PI*frequency*component_value)));
                                                                 ^
    main.c:217:17: error: invalid type argument of unary ‘*’ (have ‘double’)
                     *result_table[0][i] = temp_impedRR; // store values in array
                     ^
    main.c:218:17: error: invalid type argument of unary ‘*’ (have ‘double’)
                     *result_table[1][i] = temp_impedRI;
                     ^
    main.c:219:17: error: invalid type argument of unary ‘*’ (have ‘double’)
                     *result_table[4][i] = voltreal_C;
                     ^
    main.c:220:17: error: invalid type argument of unary ‘*’ (have ‘double’)
                     *result_table[5][i] = voltimag_C;
                     ^
    main.c:221:17: error: invalid type argument of unary ‘*’ (have ‘double’)
                     *result_table[3][i] = curreal_C;
                     ^
    main.c:222:17: error: invalid type argument of unary ‘*’ (have ‘double’)
                     *result_table[4][i] = curimag_C;
                     ^
    main.c:227:43: error: invalid operands to binary * (have ‘double’ and ‘double *’)
                 temp_impedlI = (2*PI*frequency*component_value);
                                               ^
    main.c:233:13: error: invalid type argument of unary ‘*’ (have ‘double’)
                 *result_table[0][i] = temp_impedlR;
                 ^
    main.c:234:13: error: invalid type argument of unary ‘*’ (have ‘double’)
                 *result_table[1][i]    = temp_impedlI;        
                 ^
    main.c:235:13: error: invalid type argument of unary ‘*’ (have ‘double’)
                 *result_table[4][i] = voltreal_L;
                 ^
    main.c:236:13: error: invalid type argument of unary ‘*’ (have ‘double’)
                 *result_table[5][i] = voltimag_L;
                 ^
    main.c:237:13: error: invalid type argument of unary ‘*’ (have ‘double’)
                 *result_table[3][i] = curreal_L;
                 ^
    main.c:238:13: error: invalid type argument of unary ‘*’ (have ‘double’)
                 *result_table[3][i] = curimag_L;
                 ^
    main.c:246:13: error: ‘imped_real’ undeclared (first use in this function)
                 imped_real = ((temp_impedReal*0)+(temp_impedImag*temp_impedlI))/((0*0)+(temp_impedlI*temp_impedlI)); //
                 ^
    main.c:246:13: note: each undeclared identifier is reported only once for each function it appears in
    main.c:247:13: error: invalid type argument of unary ‘*’ (have ‘double’)
                 *result_table[0][component_number] = imped_real; // store in Array
                 ^
    main.c:248:13: error: ‘imped_imag’ undeclared (first use in this function)
                 imped_imag = ((temp_impedImag*0)-(temp_impedReal*temp_impedlI))/((0*0)+(temp_impedlI*temp_impedlI)); //
                 ^
    main.c:249:13: error: invalid type argument of unary ‘*’ (have ‘double’)
                 *result_table[1][component_number] = imped_imag; // store in array
                 ^
    main.c:253:13: error: invalid type argument of unary ‘*’ (have ‘double’)
                 *result_table[2][component_number] = total_curReal;
                 ^
    main.c:256:13: error: invalid type argument of unary ‘*’ (have ‘double’)
                 *result_table[3][component_number] = total_curReal;
                 ^
    main.c:268:30: error: incompatible types when assigning to type ‘double’ from type ‘double *’
                     temp_impedRR = component_value; // Temp total impedance of Resistor Real
                                  ^
    main.c:274:52: error: invalid operands to binary * (have ‘double’ and ‘double *’)
                     temp_impedCR = 0-(1/(2*PI*frequency*component_value));
                                                        ^
    main.c:279:47: error: invalid operands to binary * (have ‘double’ and ‘double *’)
                     temp_impedlR = (2*PI*frequency*component_value);  // Temp total impedance of inductor Real
                                                   ^
    main.c:286:27: error: ‘temp_impedRReal’ undeclared (first use in this function)
                 imped_real = (temp_impedRReal + 0);
                               ^
    main.c:287:13: error: invalid type argument of unary ‘*’ (have ‘double’)
                 *result_table[0][component_number] = imped_real;
                 ^
    main.c:289:13: error: invalid type argument of unary ‘*’ (have ‘double’)
                 *result_table[1][component_number] = imped_imag;
                 ^
    main.c:291:122: error: expected ‘)’ before ‘;’ token
          total_curReal = ((source_voltage*imped_real)+(0*imped_imag)/((imped_real*imped_real)+(imped_imag*imped_imag));
                                                                                                                       ^
    main.c:320:9: error: expected ‘;’ before ‘}’ token
             }
             ^
    main.c: In function ‘print_results’:
    main.c:343:25: warning: format ‘%lf’ expects argument of type ‘double’, but argument 2 has type ‘double *’ [-Wformat=]
                      printf("| %lf% |", &result_table[0][j]);
                             ^
    main.c:343:25: warning: unknown conversion type character ‘|’ in format [-Wformat=]
    main.c:344:25: warning: format ‘%lf’ expects argument of type ‘double’, but argument 2 has type ‘double *’ [-Wformat=]
                      printf("%lf%", &result_table[1][j]);
                             ^
    main.c:344:25: warning: spurious trailing ‘%’ in format [-Wformat=]
    main.c:353:25: warning: format ‘%lf’ expects argument of type ‘double’, but argument 2 has type ‘double *’ [-Wformat=]
                      printf("| %lf% |", &result_table[2][j]);
                             ^
    main.c:353:25: warning: unknown conversion type character ‘|’ in format [-Wformat=]
    main.c:354:25: warning: format ‘%lf’ expects argument of type ‘double’, but argument 2 has type ‘double *’ [-Wformat=]
                      printf("%lf%", &result_table[3][j]);
                             ^
    main.c:354:25: warning: spurious trailing ‘%’ in format [-Wformat=]
    main.c:363:25: warning: format ‘%lf’ expects argument of type ‘double’, but argument 2 has type ‘double *’ [-Wformat=]
                      printf("| %lf% |", &result_table[4][j]);
                             ^
    main.c:363:25: warning: unknown conversion type character ‘|’ in format [-Wformat=]
    main.c:364:25: warning: format ‘%lf’ expects argument of type ‘double’, but argument 2 has type ‘double *’ [-Wformat=]
                      printf("%lf%", &result_table[5][j]);
                             ^
    main.c:364:25: warning: spurious trailing ‘%’ in format [-Wformat=]
    Having fixed your result_table array issue, there are a whole host of printf/scanf format issues.
    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.

  3. #3
    Registered User
    Join Date
    Sep 2016
    Posts
    2
    Thanks! Then how do I point the array to the function in my main?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > calculate_impedance(&result_table[6], component_type, component_value, component_number, frequency, circuit_type, source_voltage);
    It's just
    calculate_impedance(result_table, component_type, component_value, component_number, frequency, circuit_type, source_voltage);
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Illegal use of floating point
    By Ajay M Katte in forum C Programming
    Replies: 2
    Last Post: 07-10-2014, 10:50 PM
  2. what is an Illegal floating point ?
    By everyone0 in forum C Programming
    Replies: 7
    Last Post: 04-27-2010, 09:07 AM
  3. Why illegal use of floating point?
    By chottachatri in forum C++ Programming
    Replies: 2
    Last Post: 03-23-2008, 07:00 AM
  4. Illegal use of floating point...(In C)
    By OmnipotentCow in forum C Programming
    Replies: 5
    Last Post: 05-31-2003, 06:26 PM
  5. Illegal use of floating point
    By Lazy Student in forum C Programming
    Replies: 5
    Last Post: 05-14-2002, 02:10 PM

Tags for this Thread