Reputation: 15
The program should find the maximum value of the array, but I'm facing an error I cannot fix.
I get the following error:
invalid conversion from 'int*' to 'int'.
Replacing int
by float
works as expected.
#include<stdio.h>
void find_biggest(int, int, int *);
int main()
{
int a[100], n, *biggest;
int i;
printf("Number of elements in array ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter the values: ");
scanf("%d",&a[i]);
}
find_biggest(a, n, &biggest); //invalid conversion from 'int*' to 'int'
printf("Biggest = %d",biggest);
return 0;
}
void find_biggest(int a[], int n, int *biggest)
{
int i;
*biggest=a[0];
for(i=1; i<n; i++)
{
if(a[i]>*biggest)
{
*biggest=a[i];
}
}
}
Upvotes: 1
Views: 61
Reputation: 669
The word find is a word reserved in langage C,you must avoid it
#include<stdio.h>
int main()
{
int a[100], n, *biggest;
int i;
printf("Number of elements in array ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter the values: ");
scanf("%d",&a[i]);
}
biggest_array(a, n, &biggest); //invalid conversion from 'int*' to 'int'
printf("Biggest = %d",biggest);
return 0;
}
void biggest_array(int a[], int n, int *biggest)
{
int i;
*biggest=a[0];
for(i=1; i<n; i++)
{
if(a[i]>*biggest)
{
*biggest=a[i];
}
}
}
Upvotes: 0
Reputation: 223699
You've got a mismatch between your function prototype:
void find_biggest(int, int, int *);
And definition:
void find_biggest(int a[], int n, int *biggest)
Since you're passing the array a
as the first argument, the definition is correct and the prototype is incorrect. Change it to:
void find_biggest(int [], int, int *);
Or:
void find_biggest(int *, int, int *);
You're also passing the wrong type for the third argument. You define biggest
as an int
pointer and are passing its address, so the given parameter has type int **
when it expects int
. So change type type of biggest
to int
.
int a[100], n, biggest;
Upvotes: 1