Monday, August 26, 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)
hard drive - Leaving bad sectors in unformatted partition?
Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...
-
This question is prompted by the following regularly observed phenomena I'd like to find an explanation for: Current commit is regularly...
-
I'm currently trying to set up my environment such that I can open a ConEmu tab and it will automatically initialize Far Manager and the...
-
Before taking ownership of files and folders I would like to understand how to view the current permissions so that they may be reverted. I ...
No comments:
Post a Comment