I don't know how to use int&x in the C language header file.

Asked 1 years ago, Updated 1 years ago, 320 views

I would like to obtain the minimum value, maximum value, sum, mean, variance, and standard deviation of the array in the source.c file from BigArray.c and forward it to source.c. I understand that you use int&x to pass multiple things in a function. How do I use it in other files?

Source.c

#include <stdio.h>
#include <conio.h>
#include <math.h>
#include "BigArray.h"
#define Data_Output_File "Data_output.txt"
void arrayStatistics_basicArray(FILE* fout)
{
    int num_data = 10, min, max;
    double sum, avg, var, std_dev;
    int data_array[MAX_NUM_DATA] = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
    printf("\nArrayStatistics_basicArray .....\n");
    fprintf(fout, "\nArrayStatistics_basicArray .....\n");
    getArrayStatistics(data_array, num_data, min, max, sum, avg, var, std_dev);
    printf("min(% 5d), max(% 5d), sum(% 7.2lf), avg(% 7.2lf), var(% 7.2lf),std_dev(% 7.2lf)\n", min, max, sum, avg, var, std_dev);
    printf("arrayStatistics_basicArray - completed. Result is also stored in output file(% s).\n", Data_Output_File);
}
int main(void)
{
    FILE* fout;
    fout = fopen(Data_Output_File, "w");
    if (fout == NULL)
    {
        printf("Error in creation of %s !!\n", Data_Output_File);
        return -1;
    }
    arrayStatistics_basicArray(fout);
    fclose(fout);
}

BigArray.h

#pragma once
#ifndef BIG_ARRAY_H 
#define BIG_ARRAY_H
void getArrayStatistics(int* array, int num_data, int& min, int& max, double& sum, double& avg, double& var, double& std_dev);
#endif

BigArray.c

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void getArrayStatistics(int* array, int size, int& min, int& max, double& sum, double& avg, double& var, double& std_dev)
{
    double sum_sq_diff = 0.0;

    for (int i = 0; i < size; i++) 
    {
        sum += array[i];
    }
    avg = sum / size; 
    for (int i = 0; i < size; i++) 
    {
        sum_sq_diff += (array[i] - avg) * (array[i] - avg);
    }
    var = sum_sq_diff / size; 
    std_dev = sqrt(var); 
}

Error

Error (active) Unnamed prototype parameters are not available when E0141 body is present. (Line 6)
Error (active) E0018 ') is required. (Line 6)  
Error C2143 SyntaxError: '') does not exist before '&'. (Line 6)
Error C2143 SyntaxError: '{' not preceded by '&' (Line 6)
Error C2059 Syntax error: '&' (line 6)
Error C2059 Syntax error: '') (line 6)
Error (active) E0020 identifier "sum"/"avg"/"var"/"std_dev" is not defined. 

c

2023-04-04 20:16

1 Answers

int&x; variables are of the type that do not exist in the C language, but only in the C++ language.

In other words, the code you just brought is C++ code.

Anyway, the extension of the current source files is .If you change from c to .cpp, it will be recognized normally.

In C language, you must write a pointer variable instead.


2023-04-05 02:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.