Thread: reoccuring conflicting types error and previous implicit declaration errors....ARGHH

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    6

    reoccuring conflicting types error and previous implicit declaration errors....ARGHH

    Code:
    #include <stdio.h>
    
    
    
    int main(void){
    
    		char c1,c2,c3,x,y,z;
    	
    		printf("Enter three capital letters: ");
    		scanf("%c%c%c",&c1,&c2,&c3);
    line 13:		order_chars(c1,c2,c3);
    		
    		printf("\nHere are your letters in alpha-betical order: %c%c%c",x,y,z);
    
    }
    
    line 19: char order_chars(char x,char y,char z){
    	
    	char c4,c5,c6;
    	
    	if(x < y){
    		x = x;
    		y = y;
    	}	
    	else{
    		c4 = x;
    		x = y;
    		y = c4;
    	}	
    	if(x < z){
    		x = x;
    		z = z;
    	}	
    	else{
    		c5 = x;
    		x = z;
    		z = c5;
    	}	
    	if(y < z){
    		y = y;
    		z = z;
    	}	
    	else{
    		c6 = y;
    		y = z;
    		z = c6;
    	}	
    return x,y,z;
    }
    How are these errors possible.....ARGGGG

    Code:
    8-7.c:19: error: conflicting types for 'order_chars'
    8-7.c:13: error: previous implicit declaration of 'order_chars' was here

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    A compiler is not going to scan ahead for you to see what functions you may have lurking at the end of your file. If it has not seen a function declaration by the time you call the function, it simply assumes that the function returns int and takes an unspecified number of arguments. This is what your compiler is referring to as an “implicit declaration”, because that's what it is.

    Either put the order_chars() function above main(), or put a prototype for it above main(). A prototype would look something like:
    Code:
    char order_chars(char x,char y,char z);
    That's enough for the compiler to know how to properly deal with the function.

    It sounds like you're using gcc. Always use at least the -Wall option; this turns on a lot of useful (and one or two stupid) warnings.

    By the way, “return x, y, z” does not do what you (probably) think it does: it returns z, and ignores x and y. You can't return multiple values in C.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    Much apreciated thank you!

Popular pages Recent additions subscribe to a feed