<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=big5">
<META content="MSHTML 6.00.2737.800" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hi,</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>The following lines just wouldn't work. Memory needs
to be allocated for the temporary string. Otherwise it's just a wild
pointer! You are probably used to Java coding?</FONT></DIV>
<DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>char *temp;</FONT></DIV>
<DIV><FONT face=Arial size=2>strcpy_P(temp,line1);</FONT></DIV>
<DIV>
<DIV><FONT face=Arial></FONT> </DIV></DIV>
<DIV><FONT face=Arial>must actually be:</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>char *temp = (char*) malloc(strlen_P(line1) +
1);</FONT></DIV>
<DIV><FONT face=Arial>if (!temp) <Do out of memory error
handling>;</FONT></DIV>
<DIV><FONT face=Arial>strcpy_P(temp,line1);</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>Remember to free the string after it's been
used.</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>free(temp);</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>Cheers,</FONT></DIV>
<DIV><FONT face=Arial>Francois</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=ivesworking@hotmail.com
href="mailto:ivesworking@hotmail.com">iVesWorking</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=en-nut-discussion@egnite.de
href="mailto:en-nut-discussion@egnite.de">en-nut-discussion@egnite.de</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Wednesday, June 30, 2004 12:00
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [En-Nut-Discussion] Passing
String between Function and Prog_char</DIV>
<DIV><FONT face=Arial size=2></FONT><FONT face=Arial></FONT><FONT
face=Arial></FONT><FONT face=Arial></FONT><FONT face=Arial></FONT><FONT
face=Arial></FONT><BR></DIV>
<DIV><FONT face=Arial size=2>
<DIV><FONT face=Arial size=2>i Had some problem of passing string from on
function to the other. </FONT></DIV>
<DIV><FONT face=Arial size=2>the case is like this</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>char *FunctionA(int a){</FONT></DIV>
<DIV><FONT face=Arial size=2>static prog_char line1 = "a";</FONT></DIV>
<DIV>
<DIV><FONT face=Arial size=2>static prog_char line2 = "a";</FONT></DIV>
<DIV><FONT face=Arial size=2>char *temp;</FONT></DIV>
<DIV><FONT face=Arial size=2>if (a==1)strcpy_P(temp,line1);</FONT></DIV>
<DIV><FONT face=Arial size=2>return temp;}</FONT></DIV></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>
<DIV><FONT face=Arial size=2>char *FunctionB(int a){</FONT></DIV>
<DIV><FONT face=Arial size=2>static prog_char line1 = "a";</FONT></DIV>
<DIV>
<DIV><FONT face=Arial size=2>static prog_char line2 = "a";</FONT></DIV>
<DIV><FONT face=Arial size=2>char *temp;</FONT></DIV>
<DIV><FONT face=Arial size=2>if (a==1)strcpy_P(temp,line1);</FONT></DIV>
<DIV><FONT face=Arial size=2>return temp;}</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV>char *functionC(void){</DIV>
<DIV>
<DIV>char *temp1;
<DIV>
<DIV>char *temp2;
<DIV>char *temp3="hello world";</DIV></DIV></DIV>
<DIV>strcpy_P(temp1,FunctionA(1));</DIV>
<DIV>
<DIV>strcat(temp1,temp3);</DIV>
<DIV>
<DIV>strcat_P(temp1,FunctionB(1));</DIV>
<DIV>return temp1;</DIV>
<DIV>}</DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV> </DIV>
<DIV>The real case the string are longer, but total length was around 30-100
char</DIV>
<DIV>anyone have this problem ? or know why this happen ?</DIV>
<DIV>or it was work flawless on your machine ?</DIV>
<DIV>i using Gcc
compiler</DIV></DIV></DIV></DIV></DIV></DIV></FONT></DIV></FONT></DIV>
<P>
<HR>
<P></P>_______________________________________________<BR>En-Nut-Discussion
mailing
list<BR>En-Nut-Discussion@egnite.de<BR>http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion<BR></BLOCKQUOTE></BODY></HTML>