Pointer swap func def error

This is a discussion on Pointer swap func def error within the C Programming forums, part of the General Programming Boards category; Hey guys I am having a bit of trouble with these errors, and I cannot see what I have done ...

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475

    Pointer swap func def error

    Hey guys

    I am having a bit of trouble with these errors,
    and I cannot see what I have done wrong. I have looked the compiler error
    number up and it says to try to
    comment out the lines above it to see the error exactly, but if I do that I will
    get a ton more cause the error line is just the function definition.

    The code swaps array elements into ascending order using pointer notation

    Code:
    #include <stdio.h>
    
    #define SIZE 10
    
    /*function prototypes*/
    void sortArray ( int*, const int );
    void swapElements ( int *const, int *const );
    
    /*main function*/
    int main ( void ) {
    	int data[ SIZE ] = { 2, 4, 6, 8, 10, 1, 3, 5, 7, 9 },
    		 counter;
    
    	printf("Original array output:\n\n");
    
    	for ( counter = 0; counter < SIZE; counter++ ) {
    		printf(" %d", data[ counter ]);
    	}
    
    	/*sort into order*/
    	sortArray( data, SIZE );
    
    	printf("\n\nSorted array output:\n\n");
    
    	for ( counter = 0; counter < SIZE; counter++ ) {
    		printf(" %d", data[ counter ]);
    	}
    
    	getchar();
    
    	return 0;
    }
    
    /*function to sort the array into acsending order*/
    void sortArray ( int *array, const int SIZE ) { ERROR LINE
    	int counter,
    		 pass;
    
    	for ( counter = 0; counter < SIZE -1; counter++ ) {
    		for ( pass = 0; pass < SIZE -1; pass++ ) { 
    			if ( array[ pass ] > array[ pass +1 ] ) { 
    				swapElements( &array[ pass ], &array[ pass +1 ] );
    			}
    		}
    	}
    }
    		
    /*function to swap the elements over usihng pointer notation*/
    void swapElements ( int *const ElementPtr1, int *const ElementPtr2 ) {
    	int temp = *ElementPtr1;
    	*ElementPtr1 = *ElementPtr2;
    	*ElementPtr2 = temp;
    }
    The errors:

    Code:
    main.c(48): error C2059: syntax error : ')'
    main.c(48): error C2059: syntax error : '<Unknown>'
    main.c(48): error C2143: syntax error : missing ')' before 'constant'
    main.c(48): error C2143: syntax error : missing '{' before 'constant'
    Im using MS VC++ 2003.net IDE

    I really appriciate any tips and help
    I'm just trying to be a better person - My Name Is Earl

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    The preprocessor substituted the identifier "SIZE" in your declaration with "10". During compilation the compiler only sees:

    Code:
    void sortArray ( int *array, const int 10 )
    Last edited by Sebastiani; 06-20-2009 at 06:07 PM. Reason: grammer bad was
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Thanks so much

    I thought it was only a small logical error. I removed the passing of SIZE and it works fine now
    I'm just trying to be a better person - My Name Is Earl

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,590
    I have one big complaint about the code, though:
    http://apps.sourceforge.net/mediawik...arameter_names
    And you shouldn't remove the parameter size; merely rename it so it doesn't conflict with the macro.
    (Which is why you should never name parameters with upper-case letters; they should be reserved for macros.)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  3. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21