Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking multiple programs

Status
Not open for further replies.

ToddT

Programmer
Feb 7, 2003
14
0
0
US
Can anyone tell me how to link multiple programs?
I'm using this
void main(int argc, char argv){
...
if(...)
system("program1");
else if(...)
system("program2");
else if(...)
system("program3");
exit(0);

But this is giving me core dumps, which I do not have access to
 
What is it that you want to do? You want to have multiple programs in one? //Daniel
 
Yes, my goal is to have one executable that feeds from the command line. This program interprets the command line and look for tokens that activate the other programs. Ex. A program right.exe that checks if a triangle is a right triangle, Count.exe that counts words in a file, and Search.exe that searches for a file. The first program will call these on tokens of -r, -c, -l. The three seperate files run correctly and the first works until it calls the others. Then I get a core dump. I can rework the first file, but I wanted to try creating seperate processes.
 
Hello


By the small code you wrote, the first things to say is that it is correct.

Then the core dump might come from what you are putting in the system call eg : "program1" "program2" etc ... I mean the core dump come from the other programs.

If I have no choice than using system command, I usually use this way :

char * command=NULL

after I count then strlen oh my command ... ex : int sizeOfCommand = strlen("triangle -r) + strlen(nameFile);

nameFile can be a char * of a name of a file you are working with in your argv.

theen I made a realloc of the NULL char pointer command with sizeOfCommand ...

I made the sprints in the command ...

then I call system(command) ...

by this way it works perfectly.

But If I can sugest you ... :

If the sources codes are not to uge and you have access of it, it is better to spend time to include those sources codes in your codes than using a system call.

If you steel have problem, tel me I will send you an exemple.

Hope it helps


lcout
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top