Home>

This site http://9cguide.appspot.com/15-q.htmlThe 15-p exercises in c language that I remember hardly seem to have different answers. I tried to fix the source myself, but it still gives an error.
I don't think anything is wrong in the sense of sending the array address to another function as an argument. What is wrong?

Error message
A description error was found in "15th line".
warning
Array initialization is incorrect.
A description error was found in "15th line".
A description error was found in "Line 23".
"Maxmin" has been redefined. Make sure that i am not using the same name as before and that the function description is correct.
warning
Array initialization is incorrect.
Applicable source code
## include<stdio.h>
void maxmin (int array [], int max, int min);
int main (void)
{
    int i = 0, array [10], max, min;
    do {
        printf ("% d th number:", i + 1);
        scanf ("% d",&array [i]);
        i ++;
    } while (array [i-1]! = -1);
    maxmin (array,&max,&min);
    printf ("Maximum value% d: Minimum value% d \ n", max, min);
    return 0;
}
void maxmin (int * array, int * max, int * min)
{
    int i = 0;
    * max = 0;
    * min = 100;
    while (array [i]! = -1) {
        if (array [i]>max) max = array [i];
        if (array [i]<min) min = array [i];
        i ++;
    }
}

I thought that the value of the argument was wrong, so I changed it, but I got an error.

Supplemental information (FW/tool version etc.)

EasyIDEC

c
  • Answer # 1

    In function definition

    void maxmin (int array [], int max, int min);


    In this way, it is assumed that "integer array", "integer" and "integer" will come.

    But what you are actually passing

    maxmin (array,&max,&min);


    "Integer type array" "integer address" "integer address" is passed.

    I think it would be ideal to set themaxandminvalues ​​on the function side, so
    Try to match the definition or call.

    Even if you remove it, you can just try the opposite, so try it for now.


    [Revised question text]

    In C language, there is a declaration part (prototype declaration) and an implementation part of a self-made function.
    In both cases, "return value type", "function name", and "argument" must be written, and they must be written in the same way.

    Rewrite the prototype declaration as well as the implementation part.

  • Answer # 2

    Fixed. The correction part has a comment of "// correction".
    First line is
    "## include"
    I think it was a copy mistake (two #), so I modified it, but I didn't add any comments.

    # include
    void maxmin (int array [], int * max, int * min);// correct
    int main (void)
    {
        int i = 0, array [10], max, min;
        do {
            printf ("% d th number:", i + 1);
            scanf ("% d",&array [i]);
            i ++;
        } while (array [i-1]! = -1);
        maxmin (array,&max,&min);
        printf ("Maximum value% d: Minimum value% d \ n", max, min);
        return 0;
    }
    void maxmin (int * array, int * max, int * min)
    {
        int i = 0;
        * max = 0;
        * min = 100;
        while (array [i]! = -1) {
            if (array [i]>* max) * max = array [i];// fix
            if (array [i]<* min) * min = array [i];// fix
            i ++;
        }
    }

Trends