Monday, 26 August 2019
c++ - crt detected that the application wrote to memory after end of heap buffer
Answer
char* SequenceTokenAnalizer::NextToken(char delim)
{
int main()
{
SequenceTokenAnalizer st1("This is a test");
char* helpSequence;
helpSequence = st1.NextToken();
cout << helpSequence << endl;
delete[] helpSequence;
}
int i = currentindex, i2 = currentindex, cnt = 0, j = 0;
char *token=NULL;
if (Sequence[i2] == delim)
{
while (Sequence[i2] == delim&& Sequence[i2] != '\0')
{
i2++;
}
while (Sequence[i2] != delim&& Sequence[i2]!='\0')
{
cnt++;
i2++;
}
token = new char[cnt];
if (Sequence[i] == delim)
{
while (Sequence[i] == delim)
{
i++;
}
while (Sequence[i] != delim&& Sequence[i2] != '\0')
{
token[j] = Sequence[i];
i++;
j++;
}
token[j] = '\0';
currentindex = i;
return token;
}
}
else
{
while (Sequence[i2] != delim)
{
cnt++;
i2++;
}
token = new char[cnt];
if (Sequence[i] == delim)
{
while (Sequence[i] == delim)
{
i++;
}
while (Sequence[i] != delim)
{
token[j] = Sequence[i];
i++;
j++;
}
token[j] = '\0';
currentindex = i;
return token;
}
else
{
while (Sequence[i] != delim)
{
token[j] = Sequence[i];
i++;
j++;
}
token[j] = '\0';
currentindex = i;
return token;
}
}
class:
#include
#include
using namespace std;
const int SIZE = 80;
class SequenceTokenAnalizer {
char Sequence[SIZE];
char delimiter;
int currentindex;
public:
SequenceTokenAnalizer(char str[]);
SequenceTokenAnalizer(char str[], char delim);
int LengthSequence();
int CountAllTokens();
void ResetTokens();
int CountTokens();
bool HasMoreTokens();
bool HasMoreTokens(char delim);
char* NextToken();
char* NextToken(char delim);
bool Equals(SequenceTokenAnalizer other);
bool NotEquals(SequenceTokenAnalizer other);
bool isCommonToken(SequenceTokenAnalizer other);
void PrintCommonTokens(SequenceTokenAnalizer other);
};
after using delete[] in main I get crt detected that the application wrote to memory after end of heap buffer please helppppp here i have sequences and have to return next tokken from current index
after using delete[] in main I get crt detected that the application wrote to memory after end of heap buffer please helppppp here i have sequences and have to return next tokken from current index
Subscribe to:
Post Comments (Atom)
php - file_get_contents shows unexpected output while reading a file
I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...
-
I have an app which needs a login and a registration with SQLite. I have the database and a user can login and register. But i would like th...
-
I got an error in my Java program. I think this happens because of the constructor is not intialized properly. My Base class Program public ...
-
I would like to use enhanced REP MOVSB (ERMSB) to get a high bandwidth for a custom memcpy . ERMSB was introduced with the Ivy Bridge micro...
No comments:
Post a Comment