Please help!! urgently..syntax error in function call

error says "cannot convert 'int*' to 'int' in function main()
and also
type mismatch in parameter in function sort(int,int)

heres the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<iostream.h>
#include<conio.h>
void main()
{
void sort(int,int);
clrscr();
int Arr[20],i,n;
cout<<"Enter the size of the array:";
cin>>n;
cout<<"Enter the elements of the array:";
for(i=0;i<n;i++)
cin>>Arr[i];
cout<<"The unsorted array is...\n";
for(i=0;i<n;i++)
cout<<Arr[i]<<" ";
sort(Arr,n);
getch();
}
void sort(int A[],int num)
{
int i,j,small,pos;
for(i=0;i<num;i++)
{
small=A[i];
pos=i;
for(j=i+1;j<num;j++)
if(A[j]<small)
{
small=A[i];
pos=j;
}
}
int temp=A[i];
A[i]=A[pos];
A[pos]=temp;
cout<<"The sorted array...\n";
for(i=0;i<num;i++)
cout<<A[i]<<" ";
}
Last edited on
Your function prototype and function definition don't match. The prototype tells the compiler that the function will take two integers, but you send in and the function is defined to take an integer array and an integer.

void sort(int,int);

void sort(int A[],int num)
wildblue, so how shud the prototype be?
should it be sumthing like
 
void sort(int A[],int);
The A isn't necessary, but the [] is, it tells the compiler to expect an array.
so
 
void sort(int[],int)
,right? or shud there be space between int and []?
Shouldn't matter whether you have a space there or not.
man output is wrong. when i enter 1,2,4,5,3
unsorted is 1 2 4 5 3
but sorted is 1 2 4 5 9215
help
If your sort logic isn't working, might be good to step through the sort function to see how the values are changing (or not).
i'll try pls wait
Also - the function prototype (line 5) should get pulled out of the main function and be put before main begins.
oh man, no idea where i went wrong. can u pls find it out? i gotta submit this program tomorrow.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
	for(i=0;i<num;i++)
	{
		small=A[i];
		pos=i;
		for(j=i+1;j<num;j++)
			if(A[j]<small)
			{
				small=A[i];
				pos=j;
			}
	}
	//here i==num
	int temp=A[i]; //out of bounds access
	A[i]=A[pos];
	A[pos]=temp;
notice, thanks to indentation, how your "swap" is outside the loop
Topic archived. No new replies allowed.