The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 C functions across c files

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
peter.cook Posted - 01/28/2004 : 6:12:20 PM
Hi,

Probably displaying my lack of programming expertise here ...but how do I make a function in one C file usable in another C file? The particular case would be two C files attached to a project ot one attached and one in the client folder.

Thanks in advance,

Cheers,

Pete

1   L A T E S T    R E P L I E S    (Newest First)
cpyang Posted - 01/28/2004 : 6:31:44 PM
You will need to create a header file and prototype the functions that are going to be shared, like

my_share.h

bool my_func(int nVal = 0);

my_share.c


bool my_func(int nVal)// = 0);
{
// actual codes
return true;
}


Alternatively, a better approach would be to create a class and have everything in a single header file. You can find one such example in

OriginC\System\Profiler.h

Since all the member functions are implemented inside the class, then you can just include this in any file that you will need to use this class. For example,

myTest.h


class myTest
{
myTest() // constructor
{
m_str = "Hello world\n";
}
public:
void DoSomething()
{
printf(m_str);
}
private:
string m_str;
};




then in one of your C file, then just


#include <origin.h>
#include "myTest.h" // header in same path as c file

void test()
{
myTest tt;

tt.DoSomething();
}





CP




Edited by - cpyang on 01/28/2004 11:10:12 PM

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000