I've been sitting here for hours trying to figure this out. I haven't been able to find a similar problem (although I'm sure it has been done). So on to my question. When I compile this, it is fine.
I should add that unsortedList is Book*, which is a struct.
string tit = tempBook->title;
string act = tempBook->action;
string aut = tempBook->author;
string sub = tempBook->subject;
char* tm = tempBook->time;
unsortedList[unsortedArrayLength].title;
unsortedList[unsortedArrayLength].action;
unsortedList[unsortedArrayLength].author;
unsortedList[unsortedArrayLength].subject;
unsortedList[unsortedArrayLength].time;
However, when I compile this, I receive an error:
Exception thrown at 0x5AC6516F (vcruntime140d.dll) in Assign.exe: 0xC0000005: Access violation writing location 0x00000000.
string tit = tempBook->title;
string act = tempBook->action;
string aut = tempBook->author;
string sub = tempBook->subject;
char* tm = tempBook->time;
unsortedList[unsortedArrayLength].title = tit;
unsortedList[unsortedArrayLength].action = act;
unsortedList[unsortedArrayLength].author = aut;
unsortedList[unsortedArrayLength].subject = sub;
unsortedList[unsortedArrayLength].time = tm;
And then it pops up window memcpy.asm with the cursor at this location:
CopyUpByteLoop:
mov al, byte ptr [esi]
mov byte ptr [edi], al
inc esi
inc edi
dec ecx
jne CopyUpByteLoop
The definition of struct Book as requested:
struct Book
{
std::string title;
std::string author;
std::string subject;
char* time;
std::string action;
};
Here is the complete function:
void DB::insertBook(Book* tempBook)
{
using namespace std;
unsortedArrayLength++;
string tit = tempBook->title;
string act = tempBook->action;
string aut = tempBook->author;
string sub = tempBook->subject;
char* tm = tempBook->time;
unsortedList[unsortedArrayLength].title = tit;
unsortedList[unsortedArrayLength].action = act;
unsortedList[unsortedArrayLength].author = aut;
unsortedList[unsortedArrayLength].subject = sub;
unsortedList[unsortedArrayLength].time = tm;
system("cls");
cout << "You have " << unsortedList[unsortedArrayLength].action <<":\n" << endl <<
unsortedList[unsortedArrayLength].title << endl <<
unsortedList[unsortedArrayLength].author << endl <<
unsortedList[unsortedArrayLength].subject << endl <<
"on " << unsortedList[unsortedArrayLength].time << endl << endl;
printToLog(tempBook);
}
Please help Obi-Wan. You're my only hope...
Okay, I figured it out. I made the instantiation of the array bigger. It appeared I was hitting the upper bounds of the array. The array was initialized with 2, which I though would be enough, but however it was not. :( Thank you to all lent me their knowledge.