[En-Nut-Discussion] Passing String between Function and Prog_char
    Francois Rademeyer 
    francois at asnone.com
       
    Wed Jun 30 12:49:59 CEST 2004
    
    
  
Hi,
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?
char *temp;
strcpy_P(temp,line1);
must actually be:
char *temp = (char*) malloc(strlen_P(line1) + 1);
if (!temp) <Do out of memory error handling>;
strcpy_P(temp,line1);
Remember to free the string after it's been used.
free(temp);
Cheers,
Francois
  ----- Original Message ----- 
  From: iVesWorking 
  To: en-nut-discussion at egnite.de 
  Sent: Wednesday, June 30, 2004 12:00 PM
  Subject: [En-Nut-Discussion] Passing String between Function and Prog_char
  i Had some problem of passing string from on function to the other. 
  the case is like this
  char *FunctionA(int a){
  static prog_char line1 = "a";
  static prog_char line2 = "a";
  char *temp;
  if (a==1)strcpy_P(temp,line1);
  return temp;}
  char *FunctionB(int a){
  static prog_char line1 = "a";
  static prog_char line2 = "a";
  char *temp;
  if (a==1)strcpy_P(temp,line1);
  return temp;}
  char *functionC(void){
  char *temp1; 
  char *temp2; 
  char *temp3="hello world";
  strcpy_P(temp1,FunctionA(1));
  strcat(temp1,temp3);
  strcat_P(temp1,FunctionB(1));
  return temp1;
  }
  The real case the string are longer, but total length was around 30-100 char
  anyone have this problem ? or know why this happen ?
  or it was work flawless on your machine ?
  i using Gcc compiler
------------------------------------------------------------------------------
  _______________________________________________
  En-Nut-Discussion mailing list
  En-Nut-Discussion at egnite.de
  http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.egnite.de/pipermail/en-nut-discussion/attachments/20040630/a6731a97/attachment.html>
    
    
More information about the En-Nut-Discussion
mailing list