Well how are you calling your C program?
Does Java have anything like popen() as a call?
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
2. But the problem i am facing now is that the printf statement that i wrote in my demo C program is being output only in the Command prompt screen, not in the Text area which i have for the input and output to the C program. As we all know that C returns only int, float double etc. i am facing this problem.
If anybody helps i will be grateful!
Are these programs run in MS-Windows os? If yes, then when the C program starts you can delete the C's command-prompt window, C program prints everything to a file, then when back to Java program have it read the data file and display the info in its window.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>Erm.. I think you are creating an array of 40 char pointers... Not sure tho.
Nope, it is declaring a pointer to an array of 40 chars
What you are describing would be:
char *str[40];
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
Thanks for pointing that out Aia.
Still I'd like to suggest changing it to the above code for readability. It seems like you don't need to make it a pointer. If you still like it to be a pointer, you can allocate some memory? I don't see the use of it, and it does make the program a bit more difficult imho.
I don't want to give the impression that char (*str)[40] is a valid string of 40 characters, ready to hold any 40 chars, automatically without the need to allocate memory for it. It is not. Since it is a pointer it needs to be initialized to point to something meaningful, but can only point to 40 chars.
/* This will work */
char string[] = "123";
char (*ptr)[4];
ptr = &string; /* notice that it is not ptr = string or ptr = &string[0] */
/* this will not work */
char string[] = "1234"; /* array is bigger than 4 */
char (*ptr)[4];
ptr = &string;
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218