Saturday, May 22, 2010

Why i can't call the fun using turbo c++?I tried below c pgm in Dev C++.i got the result.what may be the prob?

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


main()





{


int i;


int marks[]={78,67,87,56,90,78,56};





for(i=0;i%26lt;=6;i++)


display(marks[i]);


}


display(m)


int m;


{


printf("The marks are=%d",m);


}








I will get the error- "Call to undefined fn 'display' in fn main.





plz....solve this.


Thanks in advance.

Why i can't call the fun using turbo c++?I tried below c pgm in Dev C++.i got the result.what may be the prob?
some compliers work differntly on definitions.





would you need to do (its good practice anyway) is define display before it is used





void display(int val);





int main() ...
Reply:you have to define a function BEFORE you use it! Move the definition of display to above its reference in main, OR put a function prototype at the top, also define it like this:





display(int m)


{


printf("blabla= %d",m);


}





really you should just add


display(int m);


to the top of the program right after the #includes.
Reply:are u missing a directory/file name/identifirer
Reply:or you can declare it first all your functions,


then the main body of the program,


and then the definition of the function(s) you declared..





ex..


--------------------------------------...


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





void display(int m);





void main()


{


int i;


int marks[]={78,67,87,56,90,78,56}...





for(i=0;i%26lt;=6;i++)


display(marks[i]);


}





void display(int m)


{


printf("The marks are=%d",m);


}


--------------------------------------...





that is how to manage source code(s)..


you separate the declarations and the definitions of your


functions.. btw, it is actually a programming technique to


manage thousands of line of C/C++ codes.. :)


No comments:

Post a Comment