Error while using strcat() in JNI

Malcolm Kay malcolm.kay at internode.on.net
Thu Jun 4 05:14:46 UTC 2009


On Thu, 4 Jun 2009 07:08 am, Deshmukh, Pramod wrote:
> Below is the c program which is called by java. Java passed
> string object to this method which is converted to char *.
> When I print using printf() function it prints the string
> (char *), but strcat() does not like char *.
>

cmdOpenSsl = "echo -n ";

Under modern versions of C literal strings often reside in 
program memory rather than data memory and therefore cannot be 
changed. (Memory exception)

But even if your compiler places this string in data memory you
have made no provision for space to add the suffix.

Note also that in C, duplicate literal strings may be 
implemented as a single string so that if you do manage to change 
one then the other will also (mysteriously) change.

So you need something like:
 char *cmdOpenSsl;
 cDesc=strdup(....);
 cmdOpenSsl=malloc(strlen("echo -n ")+strlen(cDesc)+1);
 strcpy(cmdOpenSsl,"echo -n ");
 strcat(cmdOpenSsl,cDesc);

The problem would appear to have nothing to do with java.


>
>
> Attached is the .h file the same. Please help me. Also I have
> attached the .log file
>
>
>
> Thanks in Advance.
>
>
>
> --Pramod
>
Best of luck,

Malcolm



More information about the freebsd-java mailing list