I am writing a routine that take away integers indigenous a user and also sorts castle in ascending order. I understand the procedure of many of the steps however our teacher has said the the actual role that determines which of two variety elements is bigger must be excellent from another .c file. I"m not fairly sure just how the calling of another file works. Below is the password I have actually so far.p1.c:

You are watching: C++ call function from another file

/* This regime in its totality takes a list of integers indigenous a user and arranges castle in ascendingorder */#include#include "temp.h"#define note "Enter as much as 10 integers, finishing with -1:"#define TOO_MANY "Exceeded maximum selection size."main(void){ char input = "0"; int x, i, j, temp1, temp2, temp; puts(PROMPT); gets(input); for(i = 0; ns
#include#include "temp.h"int larger(int a, int b) if(a > b) temp = a; rather temp = b; return temp;
The teacher listed us through the temp.h and also says that the larger() role must be characterized in temp.c. So currently that I have actually that, exactly how do I access the role from p1.c?And will the "temp" variable went back in the larger() duty be obtainable from p1.c in the manner I"ve written?


Deathray Engineer
Join date Mar 2007Posts 3,211
This heat indirectly imports the explanation of the duty so once you translate into it, that knows that there must be a role somewhere v that name and also signature. That method you have the right to simply speak to the function. Usage it in every .c paper that requirements to usage that role (or in the case of temp.c whereby it demands to specify the function).When girlfriend compile, you have to specify all of the .c records to compile, consisting of the one that has actually the definition of the function(s) asserted in temp.h. The compiler (or perhaps more properly, the linker) is tasked v figuring out how to placed it all together.

Registered User
Join day Jan 2002Location northern Virginia/Washington DC metropolitan AreaPosts 3,817
And will certainly the "temp" variable reverted in the larger() function be obtainable from p1.c in the manner I"ve written?
You don"t use the return worth at every within the P1.C source file. You"d need to assign the return value from the role call to among your variables to use it in some way.

See more: Let Your Dreams Be Bigger Than Your Fears, “ And Your Actions

"Owners of dog will have noticed that, if you administer them v food and also water and also shelter and affection, they will think you are god. Whereas owner of cats are compelled to establish that, if you administer them through food and also water and also shelter and also affection, they draw the conclusion the they are gods."-Christopher Hitchens