0

I'm having some problem with a conflicting type that I don't understand. I want to change a date previously set but it's giving me a headache.

int main(){
float any=11;
llegirany(&any);
printf("%f",any);
getch();    
}

void llegirany(float * any){    
float auxi; 
auxi=llegirinterval(1,31);  
*any= auxi;
}

float llegirinterval(float n1,float n2){
float aux;
       do{          
            scanf("%f",&aux);
        }while(aux>n2 || aux<n1);
return aux;
}

And I get this output error:

65 7 D:\DAM\PRo\pruebaconio.c [Error] conflicting types for 'llegirinterval' 62 7 D:\DAM\PRo\pruebaconio.c [Note] previous implicit declaration of 'llegirinterval' was here

Can somebody help me please?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Asdemuertes
  • 313
  • 3
  • 6
  • 19

2 Answers2

3

You are using the function llegirinterval before declaring it.

You should move the definition of llegirinterval before the definition of llegirany or at least declare llegirinterval before it's used.

Check the difference between definition and declaration

EDITED following @Olaf comment.

Community
  • 1
  • 1
xabitrigo
  • 1,341
  • 11
  • 24
1

Try adding a declaration to the function llegirinterval() before you use it. You should also declare other functions contained in the code as well:

void llegirany(float *any);
float llegirinterval(float n1,float n2);

int main(){
    float any=11;

...

void llegirany(float * any){
    float auxi;
    auxi=llegirinterval(1,31);
    *any= auxi;
}

By default, C considers the type of any variable name that has not been explicitly typed yet as int. So, when it sees the call to:

llegirany(&any);

in the third line of main, the compiler says "aha, a function named llegirany that returns an int.

Later on, when the compiler gets to the actual function definition for the function, it gets confused -- wait, I thought that llegirany returns an int, and now you tell me it returns a float.

Jay Elston
  • 1,978
  • 1
  • 19
  • 38