954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

compiler as the final year project.

I have posted the related topic in the Java forum!

Now, i am having a very differnet problem altogether.

1. i am being able to call the C program from the Java frame using a "Button" in the inteface.

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!

mdew_47
Light Poster
29 posts since Jul 2008
Reputation Points: 8
Solved Threads: 0
 

Well how are you calling your C program?

Does Java have anything like popen() as a call?

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

Can can get this in the thread i posted in the Java forum, with the same name as this.

mdew_47
Light Poster
29 posts since Jul 2008
Reputation Points: 8
Solved Threads: 0
 

to my knowledge it depends on the compiler your using, i have a borland c compiler, which outputs all programs in cmd, or atleast they must be run from cmd.
but i also have anouther compiler called lcc-win32, which gives the options to open in windows mode, but i dont know enough about C to configure the compiler so im sticking with borland compiler.
so i think your java interface is making a command line only program???
my advice would be to downlaod an actual c compiler for making c programs and use java for java.

coolkeg
Newbie Poster
11 posts since Aug 2008
Reputation Points: 19
Solved Threads: 0
 
to my knowledge it depends on the compiler your using, i have a borland c compiler, which outputs all programs in cmd, or atleast they must be run from cmd. but i also have anouther compiler called lcc-win32, which gives the options to open in windows mode, but i dont know enough about C to configure the compiler so im sticking with borland compiler. so i think your java interface is making a command line only program??? my advice would be to downlaod an actual c compiler for making c programs and use java for java.


Thanks a lot, but ur suggestion is of no use to me!

I am using microsoft c, c++ and its command is Cl/LD progname.c try using it.

mdew_47
Light Poster
29 posts since Jul 2008
Reputation Points: 8
Solved Threads: 0
 

i have received what is there in my JAVA interface as a string.

Now i need scan the lines starting with #s and ending with s#. so that i could convert the string between them to capital using strupr. suggestions will be appreciated.

mdew_47
Light Poster
29 posts since Jul 2008
Reputation Points: 8
Solved Threads: 0
 

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
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

• • • • Originally Posted by mdew_47 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.


i have completed that part. i am using windows Xp. i brought all the thing to text area and output is given in the text area itself.

but since i am using JNI i am having difficulty changing the C-style string object
to general character array. so that i could perform some operations on it.

i need scan the string between #s s#. so that i could convert the string between them to capital using strupr. suggestions will be appreciated.

mdew_47
Light Poster
29 posts since Jul 2008
Reputation Points: 8
Solved Threads: 0
 

I must admit I don't know 100% what you're trying to do, but as far as I know, a C-style string object _is_ a general character array. Maybe you can create a function that returns a and print that to your textbox? Make sure the memory the is pointing to is valid though.

Clockowl
Posting Whiz
376 posts since May 2008
Reputation Points: 69
Solved Threads: 28
 

i am doing as follows:

# include <C:\j2sdk1.4.2_03\include\jni.h>
# include <C:\Program Files\InstallShield\InstallShield for Microsoft Visual C++ 6\Include\project.h>
# include <stdio.h>
# include <string.h>

JNIEXPORT jstring JNICALL Java_project_test
 (JNIEnv *env , jobject obj, jstring s)
{
char (*str)[40] =(*env)->GetStringUTFChars(env,s,0);
int i;
for(i=0;(*str)[0]=='^'&&(*str)[1]=='c';i++)
do{
strupr(str);
}while((*str)[i]!='c'&&(*str)[i+1]!='^');
return((*env)->NewStringUTF(env,str));
(*env)->ReleaseStringUTFChars(env,s,str);
}

if anyone can help i will be very thankful.

mdew_47
Light Poster
29 posts since Jul 2008
Reputation Points: 8
Solved Threads: 0
 

Erm.. I think you are creating an array of 40 char pointers... Not sure tho.

char (*str)[40] =(*env)->GetStringUTFChars(env,s,0);


Try this:

char str[40];


Sameseem to be errors in your loop. You are dereferencing str, making it a ... This is not needed and quite possibly wrong. If you want to access element 0 of str, you do it like this:

str[0]
Clockowl
Posting Whiz
376 posts since May 2008
Reputation Points: 69
Solved Threads: 28
 

>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.

Clockowl
Posting Whiz
376 posts since May 2008
Reputation Points: 69
Solved Threads: 28
 

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
 

Lessons in pretty advanced C for me. Never seen it used before.

Clockowl
Posting Whiz
376 posts since May 2008
Reputation Points: 69
Solved Threads: 28
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You