debugging issue

I've copied this code from my book and i'm at a loss for figuring out what is wrong with it. Could someone help me and explain? Thanks

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* Nick Vincent */
/* Fig. 7.15: fig_15.c
   This program puts values into an array, sorts the values into ascending order, and prints the resulting array. */
#include <stdio.h>
#define SIZE 10

void bubbleSort( int * const array1, const int SIZE ); /* prototype */

int main( void )

{
	/* initialize array a */
	int a[ SIZE ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };

	int i; /* counter */

	printf( "Data items in original order\n" );

	/* loop through array a */
	for ( i = 0; i < SIZE; i++ ) {
		printf( "%4d", a[ i ] );
	} /* end for */

	bubbleSort( a, SIZE ); /* sort the array */

	printf( "\nData items in ascending order \n" );

	/* loop through array a */
	for ( i = 0; i < SIZE; i++ ) {
		printf( "%4d", a[ i ] );
	} /* end for */

	printf ("\n");

	return 0; /* indicates successful termination */

} /* end main */

/* sort an array of integers using bubble sort algorithm */
void bubbleSort( int * const array1, const int size )
{
	void swap( int *element1Ptr, int *element2Ptr ); /* prototype */
	int pass; /* pass counter */
	int j; /* comparison counter */

	/* loop to control passes */
	for ( pass = 0; pass < size - 1; pass++) {

		/* loop to control comparisons during each pass */
		for ( j = 0; j < size - 1; j++ ) {

			/* swap adjacent elements if they are out of order */
			if ( array1[ j ] > array1[ j + 1 ] ) {
				swap( &array1[ j ], &array1[ j + 1] );
			} /* end if */

		} /* end inner for */

	} /* end outer for */

} /* end function bubbleSort */

/* swap values at memory locations to which element1Ptr and
   element2Ptr point */
void swap( int *element1Ptr, int *element2Ptr )
{
	int hold = *element1Ptr;
	*element1Ptr = *element2Ptr;
	*element2Ptr = hold;
} /* end function swap */


Is the code compiling?
Last edited on
void swap( int *element1Ptr, int *element2Ptr ); /* prototype */ on the line 42 have to be removed .
Ignore previous reply.

The problem is that the declaration:

 
void bubbleSort( int * const array1, const int SIZE ); /* prototype */


is invalid because SIZE is #defined to be 10, so the above line is really:

 
void bubbleSort( int * const array1, const int 10 ); /* prototype */

sorry for such a delayed reply. i've attempted both bluecoder's answer and jsmith's answer and neither seem to have any effect on the errors.

Are there any other possibilities?
What exactly are the error messages that you are getting?
Sorry, I've finally figured out the issues i had, i had to change the line that jsmith stated with out the const int 10.

now it works fine.
Topic archived. No new replies allowed.