Combining two programs into one in C

  • Thread starter kthouz
  • Start date
  • Tags
    Programs
In summary, the conversation discusses the possibility of combining two programs in C by using the #include preprocessor directive or system calls like exec(). Additionally, the conversation mentions the option of creating a library or archive of modules. The topic of string libraries is also briefly touched upon, with a reference to functions in the string.h header file.
  • #1
kthouz
193
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
  • #2
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
 
  • #3
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.
 
  • #4
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!?
 
  • #5
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
 

What is the purpose of combining two programs into one in C?

Combining two programs into one in C allows for more efficient and organized code. It can also improve the overall performance of the program by reducing the number of external function calls.

Can any two programs be easily combined into one in C?

No, not all programs can be easily combined into one. The two programs must have compatible syntax and functions in order for them to be successfully combined.

What is the process for combining two programs into one in C?

The process typically involves understanding the code of both programs, identifying any potential conflicts or incompatibilities, and then integrating the code together by making necessary adjustments and modifications. It is important to test the combined program thoroughly to ensure it functions correctly.

Are there any potential issues or challenges when combining two programs into one in C?

Yes, there can be potential issues such as conflicting variable names, different data types, and incompatible functions. These issues must be addressed and resolved in order for the combined program to function correctly.

What are the benefits of combining two programs into one in C?

Combining two programs into one can improve code organization, reduce the number of external function calls, and potentially improve the overall performance of the program. It can also make it easier to maintain and update the code in the future.

Similar threads

  • Programming and Computer Science
Replies
22
Views
921
  • Programming and Computer Science
Replies
7
Views
468
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
11
Views
1K
Replies
6
Views
1K
  • Programming and Computer Science
Replies
8
Views
877
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
17
Views
1K
  • Programming and Computer Science
Replies
10
Views
1K
Back
Top