tags:

views:

97

answers:

3

Dene2.c

int main ( void )
{
    fprintf ( stdout , "WAİTİNG for a sec to breath\n" ) ;

    #command_go "dene.c"

    return 0 ;
} 

dene.c

int main ( void )
{

     void wait ( int ) ;

     getdata ( a );
     showdata ( a );
     **  #command_go  "dene2.c" **

     wait ( seconds );

     return 0;   
  } 

  void getdata ( char * b )
  {
  }
  void showdata ( char * b )
  {
  } 
  void wait ( int seconds )
  {
        clock_t endwait = clock ( );
        endwait = clock ( ) + seconds * CLOCKS_PER_SEC ;
        while ( clock ( ) < endwait ) { }
  }

I simply want connect two different c file,Can I do when I write something like #command_go "dene2.c" , I want activate other file

+1  A: 

First you should rename main function in Dene2.c into something different since that name is used to decide which is the entry point of your binary file and you shouldn't have two functions with that name.

Second thing, you must write an header file for Dene2.c, called Dene2.h, that has the signature of the methods you want to call from outside. In your case your header file will be something like

int function(void);
// as we said maid needs to be changed to something different

Third you add in the beginning of Dene2.c and dene.c the include directive:

#include "Dene2.h"

Now you can safely use the function in dene.c:

...
function();
...
Jack
bad idea , if he needs how he call outside function, he will ask in other way
gcc
@gcc: it's entirely unclear what he is asking. Given the question I would be entirely unsurprised if a simple function call is exactly what is needed.
wnoise
A: 

There are two ways to go about this: Either compile two modules separately and simply execute the other file using whatever process creation mechanism your target platform supports, or simply declare a regular function in your second module (i.e. dene2.c), call the function from dene.c and link both modules together.

Jim Brissom
+1  A: 

Files, (well the C standard actually talks about "compilation units") do not do anything, do not perform. Their intended use is to organize functions in related groups. Functions and programs (which may be made of multiple linked compilation units) are what do things.

If you want one function to call another, just do so. You will need to properly declare it, of course. If it is in a separate file, the recommended way to do this is to create a "header file" with the declaration that can be #included in both the file implementing the function to be called, and the file with the function that calls.

If, instead, you want multiple threads of execution, there is no portable way to do it. It is platform dependent. Windows has a set of threading abilities, details of which Microsoft documents. Most Unix platforms use an API known as pthreads.

Finally, you may want two different programs to communicate. This is known as interprocess communication (IPC). This too is platform dependent.

wnoise