How can I insert another program in my program in C.

  • Thread starter pursis
  • Start date
  • Tags
    Program
In summary, the conversation discusses three options for incorporating a friend's code into the speaker's own code. These options include creating a library of the friend's code, referencing the code in an include file, or directly pasting the code into the speaker's code. Each option has its own drawbacks, but the first option is preferred for its modularity. The conversation also includes a playful exchange between two individuals.
  • #1
pursis
1
0
I have to insert my friend coding in mine and I don't know how to do it can someone help me.
 
Technology news on Phys.org
  • #2
  1. Compile the different parts as object files and link them together.
  2. #include
  3. Cut and paste
 
  • #3
To be clear DrClaude's suggestions are choices and not steps.

1 You can create a library of your friends code and then call his functions in your code. You may also need to create an include file of your friends function definitions to go along with the library and to be referenced in your program.

2. Alternatively, you can place your friends code in an include file and then reference it in your code some everything compiles together as one unit.

3. Lastly, you can simply paste your friends code into your own and then compile the code as one unit.

Professional programmers will also choose the first one as this makes things totally modular. It allows your friend to edit his code and you to edit your own and then you bring your code together at build time.

Choice two has the drawback that if you do a compile and your friend is still making changes then it will stop you from building your code until he/she has fixed their compiler issues.

Choice three has the drawback that you are basically grabbing a snapshot of your friends code and will need to delete and replace each time your friend makes changes.

-- Jedi

-------------------------------------------
Your choice is simple: join us and live in peace, or pursue your present course and face
obliteration. We shall be waiting for your answer. The decision rests with you.

Klaatu, The Day The Earth Stood Still (1951)
 
  • #4
Thank you for clarifying my answer, jedishrfu. I often don't put more effort in my answers than the OP put in their questions :smile:
 
  • Like
Likes Borg and jedishrfu
  • #5
Yes, we mentors are in awe of you Science Advisors and always look for the opportunity of one-upmanship.

Take care
 
  • #6
DrClaude said:
Thank you for clarifying my answer, jedishrfu. I often don't put more effort in my answers than the OP put in their questions :smile:
Seems reasonable to me...
 

What is the syntax for including another program in my C program?

The syntax for including another program in your C program is:
#include

Do I need to declare any variables before including another program in my C program?

No, you do not need to declare any variables before including another program in your C program. However, you will need to provide any necessary input variables when calling a function from the included program.

Can I include multiple programs in my C program?

Yes, you can include multiple programs in your C program by using multiple #include statements at the beginning of your code.

How can I ensure that the included program does not interfere with my main program?

You can avoid any potential interference between the included program and your main program by using unique variable names and properly structuring your code. It is also important to understand the functions and variables being used from the included program.

Is there a limit to the size or complexity of the included program in my C program?

No, there is no specific limit to the size or complexity of the included program in your C program. However, it is important to consider the overall efficiency and readability of your code when including larger or more complex programs.

Similar threads

  • Programming and Computer Science
2
Replies
37
Views
2K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
33
Views
2K
  • Programming and Computer Science
Replies
8
Views
866
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
722
  • Programming and Computer Science
Replies
1
Views
1K
Back
Top