<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=320101110-30062004></SPAN></FONT> </DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=320101110-30062004>You a
are copying a string into temp but you have not declared any space for temp -
temp is just a pointer and you have not pointed it anywhere. You need to reserve
memory if you want to store a string at this location e.g. char
temp[10];</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=320101110-30062004></SPAN></FONT> </DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=320101110-30062004>Even
with this you should not be returning temp as it is a local variable and will no
longer "exist" once the function returns. You could make it static but it is not
good programming practice to make variables static unless they need to be. A
better (and standard) solution is to specify where you want the string copied to
when you call the function (but remember to allocate space for the sting
first)</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=320101110-30062004></SPAN></FONT> </DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=320101110-30062004></SPAN></FONT> </DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=320101110-30062004>so
change</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=320101110-30062004></SPAN></FONT> </DIV>
<DIV><FONT><SPAN class=320101110-30062004>
<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><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=320101110-30062004><FONT face=Arial color=#0000ff size=2>to
</FONT></SPAN></DIV>
<DIV><SPAN class=320101110-30062004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=320101110-30062004>
<DIV><FONT face=Arial><FONT size=2><SPAN class=320101110-30062004>void
</SPAN>FunctionA(int a<SPAN class=320101110-30062004>, char
*string</SPAN>){</FONT></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(<SPAN
class=320101110-30062004>string</SPAN>,line1);</FONT><FONT face=Arial
size=2>}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><SPAN class=320101110-30062004><FONT face=Arial color=#0000ff size=2>and
call like this</FONT></SPAN></DIV>
<DIV><SPAN class=320101110-30062004><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=320101110-30062004><FONT face=Arial size=2>char
myString[21];</FONT></SPAN></DIV>
<DIV><SPAN class=320101110-30062004><FONT face=Arial size=2><SPAN
class=320101110-30062004><FONT face=Arial><FONT size=2>FunctionA( 1<SPAN
class=320101110-30062004>, myString</SPAN>);</FONT></FONT><FONT face=Arial
size=2> </FONT></SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=320101110-30062004><FONT face=Arial size=2><SPAN
class=320101110-30062004></SPAN></FONT></SPAN> </DIV>
<DIV><SPAN class=320101110-30062004><FONT face=Arial color=#0000ff size=2><SPAN
class=320101110-30062004>You also need to consider what happens to myString when
a is 0 i.e. it will not be terminated.</SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=320101110-30062004><FONT face=Arial color=#0000ff size=2><SPAN
class=320101110-30062004></SPAN></FONT></SPAN> </DIV>
<DIV><SPAN class=320101110-30062004><FONT face=Arial color=#0000ff size=2><SPAN
class=320101110-30062004>Regards</SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=320101110-30062004><FONT face=Arial color=#0000ff size=2><SPAN
class=320101110-30062004>Trevor</SPAN></FONT></SPAN></DIV></DIV></SPAN></DIV></DIV></SPAN></FONT></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B>
en-nut-discussion-bounces@egnite.de
[mailto:en-nut-discussion-bounces@egnite.de]<B>On Behalf Of
</B>iVesWorking<BR><B>Sent:</B> 30 June 2004 11:01<BR><B>To:</B>
en-nut-discussion@egnite.de<BR><B>Subject:</B> [En-Nut-Discussion] Passing
String between Function and Prog_char<BR><BR></FONT></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 color=#0000ff 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> </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> </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></BLOCKQUOTE></BODY></HTML>