0


I keep getting the error

format specifies type 'int' but the argument has type 'int ()(int , int, int)'.
printf("%d", get_max);


I'm new to pointers and coding C in general and still haven't fully grasped the language yet. I hope you can be patient in helping me fix my code and letting me understand why such error appeared. Thank you!

#include <stdio.h>

//get maximum element of array from index a to index b, inclusive

int get_max(int *array, int a, int b);


int get_max(int *array, int a, int b)
{
    int max;

    for (int j=0; j<=(b-a); j++) {

        array[j] = *(array+j+a);

        if(array[j] > array[j+1])
           max = array[j]; 
    }   

    return max;
}


int main() {

    int array[] = {1,4,-1,2,5};
    int *arr;
    int i;
    arr = array;

    printf(" PRINT ARRAY \n");

       for ( i = 0; i < 5; i++ ) {

          arr[i] = *(arr + i);

          printf("%d  ",arr[i]);
       }

    get_max(array,0,2),

    printf("MAX: %d", get_max);

return 0;
}
0

get_max is defined as a function taking 3 arguments. The error message is telling you that with this notation type 'int ()(int , int, int)'. IE a function that takes 3 arguments and returns an int.

  • set the result of get_max to something and use that in the printf or
  • print the result of get_max by composing the function properly in the printf

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .