Sunday, August 2, 2009

Simple C problem?

#include%26lt;stdio.h%26gt;


void italy();


void brazil();


void argentina();





void main()


{


printf("\nI am in main");


italy();


brazil();


argentina();


}


italy()


{


printf("\n i am in italy");


}


brazil()


{


printf("\n I am in brazil");


}


argentina()


{


printf("\nI am in argentina");


}





The error message is


type mismatch in redecleration of function italy() brazil() argetina

Simple C problem?
you forgot to write void when defining the functions, edit them as i have done below and then try, best of luck





#include%26lt;stdio.h%26gt;


void italy();


void brazil();


void argentina();





void main()


{


printf("\nI am in main");


italy();


brazil();


argentina();


}


void italy()


{


printf("\n i am in italy");


}


void brazil()


{


printf("\n I am in brazil");


}


void argentina()


{


printf("\nI am in argentina");


}





gimme the best answer vote
Reply:while defining the methods, the method signature (return type, method name and parameter list) should be same as the method prototype that has been declared in the program before using.





In your case,


you have declared the methods as





void %26lt;methodname%26gt;();





while,, when you are defing them, you are just using %26lt;methodname%26gt;() as the method signature. Hence the error you are getting.





for removing the error from your code, you simply need to add void in the method signatures. That is your modified program should look something like this :





#include%26lt;stdio.h%26gt;


void italy();


void brazil();


void argentina();





void main()


{


printf("\nI am in main");


italy();


brazil();


argentina();


}


void italy()


{


printf("\n i am in italy");


}


void brazil()


{


printf("\n I am in brazil");


}


void argentina()


{


printf("\nI am in argentina");


}
Reply:This is a type mismatch error because u hav declared the functions italy(),brazil() and argentina() to return a void type.But while defining them later in ur program u r not using void before their name.If u don't write a return type for a function then it is supposed to return an int type bydefault. So in ur definition of the functions u must write void before each functions' name.





Is it useful to u???
Reply:problem is in defining your functions, you are not writing 'void' here





correct code is





void italy()


{


printf("\n i am in italy");


}


void brazil()


{


printf("\n I am in brazil");


}


void argentina()


{


printf("\nI am in argentina");


}


No comments:

Post a Comment