Wednesday 1 February 2012

Don's answer to his question about test 4.17



you are getting that error I think because you are exiting before correcting your offset:

int length = strlen(str);

if(strOffset){
  int    locOff = *strOffset;
 if(locOff  >  length)
{

*strOffset  = length;

if( IsTextEditor)
{
return 0;
}

}

3 comments:

  1. sorry man, i saw your comment and changed the language...and thanks your feedback, im fixing it, tell you if it works later.

    ReplyDelete
  2. Sezar, remember, your logic will work for sure. But careful, as Fardad mentioned, It is not safe to use return funtion in the middle of the coding. By this way, your function will terminate without doing deleting the dynamic string at the end. So it's better to use return at the end of the function only.

    ReplyDelete
    Replies
    1. true is you have allocated a new memory then just do this :
      if( IsTextEditor)
      {
      delete [] str;
      return 0;
      }

      Delete