call functions from diferents programs


 
Thread Tools Search this Thread
Top Forums Programming call functions from diferents programs
# 1  
Old 05-18-2005
call functions from diferents programs

hi

i have ten program in C, and there are functions what are in all the programs.

so, i want to make a directory to store all the functions what are in all the programs, and call them from the C programs. (sending variables and values)

is that possible?¿? how ca i do that?¿?
any idea, thanks

jona
# 2  
Old 05-19-2005
You are saying that you have the same identical functions repeated.

move a copy of all of those functions into a separate file, like myfunctions.c
Be sure to add all of the headers (#include <> and #include "") statements you need.

Next be sure the ten source code files have the functions declared as prototypes
eg., int myfoo( char *, int); or whatever. The easy and best way is to put these prototypes in an .h file
-- let's call it myfunctions.h

In each of the ten source code files be sure to have:
Code:
#include "myfunctions.h"

in all ten files near the top.

Strip the repeated functions out of the ten source code files.

You now have choices about how you get the ten files to use the functions. One choice is to compile myfunctions.c into an object file:
Code:
cc -c myfunctions.c

this creates myfunctions.o

Then compile each of the ten source code files like this-- with myfunctions.o and myfunctions.h in the current working directory:
Code:
cc -I. fileone.c myfunctions.o -o /path/to/exectuable/fileone
...
cc -I. fileten.c myfunctions.o -o /path/to/exectuable/fileten

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Call functions from other scripts

i have a file that contains functions and i want the functions to be available in another script. of course, the ideal situation here would be to put the functions in the same script, but i dont own these scripts. so I have to call the functions file from a different script. how do i... (3 Replies)
Discussion started by: SkySmart
3 Replies

2. Shell Programming and Scripting

Help Modify call to functions depending on file name

Hi, I am creating a script that does gunzip/unzip/untar depending on the file extension. I have created 3 functions in my script and call them in following order. 1) gunzip function 2) unzip function 3) untar function I am using FILENAME=${FILENAME%.*} to modify filename between... (2 Replies)
Discussion started by: pinnacle
2 Replies

3. Shell Programming and Scripting

How to execute functions or initiate functions as command line parameters for below requirement?

I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line if then... (8 Replies)
Discussion started by: saku
8 Replies

4. Shell Programming and Scripting

How to call different programs based on requirement?

Hi Team, I have four shell scripts and i need to put it into one script and call based on requirement. For example: If server is Linux and version of my software version is 5 then it should call 1st scipt If server is Solaris and version of my software version is 6 then it should call... (16 Replies)
Discussion started by: darling
16 Replies

5. Programming

can a linux kernel module call libc functions?

can a linux kernel module call libc functions, such as printf(), strcpy(), etc...? (9 Replies)
Discussion started by: vistastar
9 Replies

6. UNIX for Dummies Questions & Answers

Are programs like sys_open( ) ,sys_read( ) et al examples of system level programs ?

Are the programs written on schedulers ,thread library , process management, memory management, et al called systems programs ? How are they different from the programs that implement functions like open() , printf() , scanf() , read() .. they have a prefix sys_open, sys_close, sys_read etc , right... (1 Reply)
Discussion started by: vishwamitra
1 Replies

7. Red Hat

Export functions in kernel module to user Programs

Hi all, I just started working on kernel modules. One query i'm not able to resolve how i can use call any of my function(take example testfunc() ) defined in my loadable kernel module (take example : test.ko) I want to export kernel module functions to user programs. Consider i have... (0 Replies)
Discussion started by: er.tarun.9986
0 Replies

8. UNIX for Dummies Questions & Answers

how to call two programs simultaneously

Hi, i want to call two programs simultaneously from a currently running program so as to distribute the job and fasten the speed. As of now I call the programs one after the other within the main program. e.g. `perl A.pl`; `perl B.pl`; how can I run the two paralelly? urgent ... please... (1 Reply)
Discussion started by: vipinccmb
1 Replies

9. Shell Programming and Scripting

Perl call C programs

Hi, I am a beginner in Perl programming. Now i need to call a C program from a perl program ...Can any one please help me and give any details how i can do this. Thanks and Regards (3 Replies)
Discussion started by: gjithin
3 Replies

10. Shell Programming and Scripting

How to call C functions in shell scripts?

How can i call dynamic C functions in shell scripts? (5 Replies)
Discussion started by: agarwal
5 Replies
Login or Register to Ask a Question