-
July 16th, 2014, 01:25 AM
#1
Debugging C++ code(Displaying char string per character)
I've tried a bunch of alternative methods to prevent an assertion error. "not understanding" the bug and why I'm getting it are relevant here, not proper, (or more appropriate), coding methods. I would write it in another way to prevent the error, I simply want to understand what is happening during run-time that causes the situation.
What is the bug?
---------------------------------------
[assertion error]
[expression _block_type_is_valid(phead->nBlockUse)]
--------------------------------
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Enter your name : ";
string Name;
cin >> Name;
// Add 1 to reserve space for a terminating null
int CharsToAllocate = Name.length() + 1;
// request for memory to hold copy of input
char* CopyOfName = new char[CharsToAllocate];
// strcpy copies from a null-terminated string
strcpy(CopyOfName, Name.c_str());
// Display the copied string
cout << "Dynamically allocated buffer contains : " << endl;
for (int placeinline = 1; placeinline <= 6; ++placeinline)
{
if (placeinline == 6)
{
cout << *CopyOfName << endl;
goto terminate;
}
else
cout << *CopyOfName << endl;
*CopyOfName++;
}
terminate:
// Done using buffer? Delete
delete[] CopyOfName;
int end;
cin >> end;
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|