This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Calling a Java program in a C program  RSS feed

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Chak
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
ex.
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);
}
strcpy(cmd,params);
System(cmd);
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,
Rgds,
Shantanu
 
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!