atya dev ,
Before telling u the Issue O wold like to Tell u some things
1 . Dont Try To return any locally declared variables to the Called
Function, caz once the function execution completed those variables
will be destroyed... as u know variables will be declared on Stack for
a Function call .
 ex :
     dont use like.
     char str[512];
    return  str;
  instead u can use like 
   char *str = new char[512];
...............
    ..............
  return str ;
is the correct code and make sure that once read the value u must destroy that 
variable  otherwise it will be a memory Leak.2.  if u create a 
vriable like     char *str[3];  -- will not create 3 
character pointers instead of 3 array of strings.    
    in ur Code u wrie as                          
printf(\"Enter the String\");                    scanf(\"%s\",str+h);  u r 
using the Array of pointers with allocating memory to Them. this is a wrong 
Code.  If at all if u want to use a Pointer to store data need to allocate 
memory.LIke...  char *str[3];  str[0] = new char[256]; like...ok. i 
think now U got the problem  in UR Code...On Mon, 2 Apr 2007 14:15:08 
+0100 (BST) [email protected] wrote                                        
              I made changes in the code main (I had problem with this code )   
 ignore previooous mail    ---------------------------------------------------  
  The purpose of the code is to return array of strings variable to main    I 
am giving input 3 strings in function call()    these strings are stored in a 
variable \"str\"    then that is returned to main, I want to print them in 
main..    if i give input as    ---------------------------    aaa    bbb    
ccc    ------------------------------    output is    ------------------------  
  aaa    garbage value    garbage value    ---------------------------------    
    I want to know why garbage values are being printed..............    
----------------------------------here is the code ----------------------    
#include        char* call()    {            int k=3,h=0;            char 
*str[3];            for(h=0;h            {                         
printf(\"Enter the String\");                    scanf(\"%s\",str+h);           
  }            return *str;    }    int main()    {            int i=3,j=0;     
       char *name[i];            *name=call();        for(j=0;j            {    
                     printf(\"The string %d\",j);                    printf(\"%s
\",name+j);            }        return 0;    }                                  
    ---------------------------------     Here’s a new way to find what you\'re 
looking for - Yahoo! Answers         [Non-text portions of this message have 
been removed]                                                        


Regards
Prashanth Kumar Chanda

[Non-text portions of this message have been removed]

Reply via email to