File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Calling a Java program in a C program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Calling a Java program in a C program" Watch "Calling a Java program in a C program" New topic

Calling a Java program in a C program

Chak Terlapu
Ranch Hand

Joined: Oct 20, 2000
Posts: 32
Hi all,
I have a C program in which I need to call a Java program. Could anyone tell me how I can do this. I also need to pass an array from my C program function to a Java program method. It would be great if anyone could help me in this.
Shantanu V

Joined: Nov 06, 2000
Posts: 1
In C there is a function called System(char *). U can make use of this to execute a OS command. The question remains how to pass an array. U can do it by passing the contents of the array as command line parameters to the java program.
suppose ur java class name is Call and u want to pass an array arr[4]= {1,2,3,4} elements to the java program, Then use the function call system as
Char *params;
Char *temp;
Char *cmd = "java Call ";
for (i=0;i<=3;i++)
temp = itoa(arr[i]);
params = strcpy(params,temp);
Just be sure u have allocated sufficient memory for the three char pointers.
And after that in Java program u can easily parse these parameters the way u need.
I think this will solve ur problem.
Pls mail me back abt this,
subject: Calling a Java program in a C program
It's not a secret anymore!