Symantec Interview Question
Senior Software Development EngineersCountry: India
Interview Type: Phone Interview
In Java, String substring method takes beginIndex and endIndex, What you described above in C++.
int substr_reentrant(char* str, char* substr_out, int outlen, int pos =0, int count=-1)
{
if (!str || *str == '\0')
{
return 0;
}
if (pos < 0 || pos >= strlen(str))
return 0;
if (count != -1)
{
if (pos+count > strlen(str))
{
return 0;
}
}
if (count == -1)
{
strcpy(substr_out, str+pos);
}
else
{
strncpy(substr_out, str+pos, count);
substr_out[count]='\0';
}
return 1;
}
I think subString() internally calls String(char[],offset,count)
- lal May 07, 2013Thats why memory lickage would be occured this is the drawback of subString()
please tell me if i wrong