'{' : missing function header

Compiler complains that '{' is missing function header when it jumps to function Sorting. But I included it in the header, or am I missing something?

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
41
 #include <iostream>
#include <conio.h>
using namespace std; 

void Sorting (int numbers[], int n);

int main()
{

const int MAX_SZ = 1000 ; 
    int numbers[MAX_SZ] = {0} ;
    int n = 0 ;


  cout << "enter  a serie of numbers, end the input with 0"<< endl ;
    int value ;
     
	for( ; n < MAX_SZ && cin >> value && value != 0 ; ++n )  
	{
		numbers[n] = value ;
	}
 
	Sorting (numbers, n);
	
_getch();
return 0;
}
void Sorting (int numbers, int n);
{     // Here pops error: expected a declaration 
	int  slask;
   for (int i=0;i<n;i++)  
         for (int j=(n-1);j>i;j--) 
             if (numbers[j-1]>numbers[j])
              {
                 slask=numbers[j-1];
                 numbers[j-1]=numbers[j];
                 numbers[j]=slask;
               }
          
} 
Last edited on
One line 28 you have to remove the semicolon.
void Sorting (int numbers, int n);
A semicolon is only allowed in the declaration.
Your prototype does not look like your actual function, which it has to.

void Sorting (int numbers[], int n);

1
2
3
4
void Sorting (int numbers, int n); // Add [] to int numbers and remove the semicolon.
{

}
Thanks! That did it.
Your function prototype and function implementation signatures don't match. Remember that there is a difference between a pointer (array) parameter and a single instance parameter.

In future please post the complete error message, these messages have important information embedded within them to aid in locating and fixing the problems.
Last edited on
I did wrote error as a comment in code. That was all the compiler said if you hover over underlined {. Unless there is something else?
Don't rely on intellinonsense errors, compile your code and then read and post the the actual error messages. The error messages generated by the compiler are usually contain much more information about the errors.

So my Visual C++ kept crushing, and i spent a couple of days strugling to get it back online, nothing. I switched to Dev C++ and finaly got back to this code. And now it stopped working... I think it worked fine, i commented even and in the saved code started making next function, but now it errors me o_O
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
41
42

#include <iostream>
#include <conio.h>
using namespace std; 

void Sorting (int numbers[], int n);

int main()
{

    const int MAX_SZ = 1000 ; // size of the array
    int numbers[MAX_SZ] = {0} ;
    int n = 0 ; // number of integers entered by the user

    cout << "enter  a serie of numbers, end the input with 0"<< endl ;
    int value ;
    
	for( ; n < MAX_SZ && cin >> value && value != 0 ; ++n )  // extracting and assigning numbers to their positions in the array 'numbers'
	{
		numbers[n] = value ;
	}
Sorting (numbers[], n);  //[Error] expected primary-expression before ']' token

	

_getch();
return 0;
}
void Sorting (int numbers[], int n)
{ 
	int  slask;
   for (int i=0;i<n;i++)  
         for (int j=(n-1);j>i;j--) 
             if (numbers[j-1]>numbers[j])
              {
                 slask=numbers[j-1];
                 numbers[j-1]=numbers[j];
                 numbers[j]=slask;
               }
        
} 

Sorting(numbers, n);
Topic archived. No new replies allowed.