Combining two programs into one in C

  • Thread starter Thread starter kthouz
  • Start date Start date
  • Tags Tags
    Programs
AI Thread Summary
Combining multiple C programs is feasible by using the #include preprocessor directive to incorporate one source file into another. Additionally, system calls like exec() can execute a compiled program from another. A common approach is to compile multiple source files together, ensuring they do not all contain a main() function. For example, a main module can call functions defined in other modules. In UNIX/Linux, this can be done using a command like `cc -o myprog prog1.c prog2.c prog3.c`. Alternatively, creating a library or archive of functions is possible, with common file types like .sl, .so, or .a used in UNIX environments. For those seeking to understand string manipulation in C, resources were suggested, including links to comprehensive lists of string functions available in string.h.
kthouz
Messages
188
Reaction score
0
Hi!
Is it possible to combine two programs in C?
I mean for example you're wriitng a program where you will need to introduce another one that you have written before and you don't need to wrest your time in rewritting it again. Then i want to know how i can create if possible a link which can let you access it where it saved on the disk. (Like those links on the web pages).
 
Technology news on Phys.org
You can use the #include preprocessor directive to include one source file inside of another. Depending upon your operating system, you can also use system calls like exec() to run a compiled program from within another.

- Warren
 
You can also write one "main()" module, then compile all three together. Assuming the other two modules are not just one giant main() each. example
Code:
// prog1.c
int foo1(int);
int foo2(int);
int main(int argc, char **argv)
{
      printf("%d\n", foo1(13) +  foo2(10));
      return 0;
}
Code:
// prog2.c
 int foo1(int val)
{
    return val+1;
}
Code:
// prog3.c
int foo2(int val)
{
    return val+val;
}

Depending on your OS and your development environment you cimpile these togetehr. Here is a UNIX/Linux example:
Code:
cc -o myprog  prog1.c prog2.c prog3.c

You can also create a library or an archive of your foo1, foo2 modules. What they are called and how to make them depends on your OS and your compiler: .sl .so .a
are common "filetypes" for these in UNIX.
 
Ok i see but i can't understand clearly. May be it is just because i still on the low level. so can you give me a link where i can learn about string library cause i guess it is that field!?
 
I don't see how string.h deals with anything in this thread :confused:
But:
A lot of the string functions start with "str" - here is a short list:
http://www.cppreference.com/all_c_functions.html

This lists all of the functions in string.h:
http://www.utas.edu.au/infosys/info/documentation/C/CStdLib.html#string.h
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top