Results 1 to 5 of 5

Thread: Problem in program of C++

  1. #1
    Join Date
    Apr 2010
    Posts
    57

    Problem in program of C++

    I have done with the basic programs of C++. But in this programming language I am getting error while doing one program. I am not able to find out an exact error in program. The following is the program :
    Code:
    char * stringTochar_array ( System: : String ^ s )
    {
    char * s = new char [ s- > Length ];
    int i = 0 ;
    while (i <s-> Length )
    {
    s [i ] = s [i ] ;
    i + + ;
    }
    l [ i ] = '\ 0 ';
    court < <" the stringtochar = "< < s < <endl ;
    return l;
    }
    calling this function is :
    Code:
    char_string hp
    while ( line ! = nullptr & & strcmp ( ch.stringTochar_array ( line) , line ) ! = 0 )
    {
    line = sr- > ReadLine ( ) ;
    }
    line = sr- > ReadLine ( );
    
    ( char_string is the name of the class that contains the " stringTochar_array ", the call is made from another class )
    Hoping that someone will help me soon.

  2. #2
    Join Date
    Mar 2008
    Posts
    227

    Re: Problem in program of C++

    There is an initial error in the function stringTochar_array: allowance must provide a character more than the length of the string :
    Code:
    char * s = new char [s-> Length + 1];
    Otherwise, the answer to your question is yes, if the class does not load string_ch to cleaning it has allocated. By cons, do not forget that each method call returns a new array of char, it is necessary to capture the function return a pointer variable.

  3. #3
    Join Date
    Mar 2008
    Posts
    232

    Re: Problem in program of C++

    I advise you to change the code calling this way :
    Code:
    char_string hp 
    char * adesallouer = null; 
    while (line! = nullptr & & strcmp (adesallouer ch.stringTochar_array = (line), line)! = 0) 
    ( 
    line = sr-> ReadLine (); 
    / / If the pointer is desaloue is a memory area 
    if (adesallouer! = null) 
    ( 
    delete adesalouer; 
    / / Do not forget to set to null for the next call. 
    adesalouer = null; 
    ) 
    ) 
    line = sr-> ReadLine (); 
    / / Note this code is like copy / paste it from above, 
    / / I advise you to add a method to optimize nettoyerCharString (char * t) 
    / / A char_string your class and call in both cases, it will be cleaner. 
    if (adesallouer! = null) 
    ( 
    delete adesalouer; 
    / / Do not forget to set to null for the next call. 
    adesalouer = null; 
    )

  4. #4
    Join Date
    Mar 2008
    Posts
    192

    Re: Problem in program of C++

    Attention function sprintf () allocates nothing. That the developer must provide a char [] big enough to receive the formatted string, always remembering to count the \ 0 fi channel. sprintf () does the same thing as printf, except that she writes from char pointer passed to it instead of writing to standard output (stdout). So do not hesitate to put more if you are not sure about the byte.!! For example :
    Code:
    char myText [20]; 
    sprintf (myText, "number =% d", 200) 
    / / should return array with n only 13

    In this example, you have to deallocate kidney, it is an automatic allocation table. By cons, if I had done:
    pmonTexte char * = new char (20);

    this will mean, when I'm done with the point, do a delete.

  5. #5
    Join Date
    Apr 2008
    Posts
    193

    Re: Problem in program of C++

    The following code will definitely help you :
    Code:
    donnee_ini class 
    ( 
    public 
    char * data (char * section, char * sousRubrique) 
    ( 
    char * s = new char [500]; 
    System:: String ^ line; 
    System:: IO:: StreamReader ^ sr = gcnew StreamReader ("thread.ini"); 
    line = sr-> ReadLine (); 
    char_string hp 
    while (line! = nullptr & & strcmp (ch.stringTochar_array (line), line)! = 0) 
    ( 
    line = sr-> ReadLine (); 
    ) 
    line = sr-> ReadLine (); 
    while (line! = nullptr & & strcmp (ch.prefixe (ch.stringTochar_array (line ),'='), sousRubrique)! = 0) 
    ( 
    line = sr-> ReadLine (); 
    ) 
    l = ch.suffix (ch.stringTochar_array (line ),'='); 
    court <<"l =" <<s <<endl; 
    return l; 
    ) 
    )

Similar Threads

  1. Jsp hello world program problem
    By Bricklayer in forum Software Development
    Replies: 6
    Last Post: 02-08-2010, 10:29 AM
  2. Problem in using regex in java program.
    By Kasper in forum Software Development
    Replies: 5
    Last Post: 05-03-2010, 05:39 PM
  3. Problem in assigning value to pointer in C-program
    By Juany in forum Software Development
    Replies: 5
    Last Post: 16-02-2010, 04:19 PM
  4. Problem in vowel counting program in c++
    By Conraad in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 09:16 PM
  5. Problem to compile a program under linux
    By Xmen in forum Software Development
    Replies: 5
    Last Post: 19-12-2009, 10:29 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,270,107.59802 seconds with 17 queries