Help! I get an 'Invalid null pointer' error

I've been trying to figure out what the invalid null pointer may be but I don't see to figure it out. Can someone help me out, maybe you can catch it?


#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

struct BookInfo
{
string book_tittle;
double price;
};

struct Author
{
string author_name;
BookInfo book_author[3];
};

//function prototype
void showInfo(Author a[], int size);
void getInfo(Author a[], int size);



int main()
{

int index =3;

Author Books[3] = { {"NONE", 0}, {"NONE", 0}, {"NONE", 0}};

showInfo(Books, index);

getInfo(Books, index);

showInfo(Books, index);

system("pause");
return 0;
}

void showInfo(Author a[], int size)
{

for(int x = 0; x < size; x++)
{
cout << "The author: " << a[x].author_name << endl;

for (int y = 0; y < size; y++)
{
cout << "\tThe title: " << a[x].book_author[y].book_tittle << ", the price: $" << a[x].book_author[y].price << endl;
}
}
}


void getInfo(Author a[], int size)
{
int x, y;

cout << "\nEnter the author's name: ";
cin >> a[x].author_name;
do
{
if (a[x].author_name == "NONE")
break;
else
for(int x =0; x < size; x++)
{
for (y=0; y < size; y++)
{
cout << "Enter tittle " << (y+1) << ": ";
cin >> a[x].book_author[y].book_tittle;
if (a[x].book_author[y].book_tittle == "NONE")
break;
else
cout << "Enter prince " << (y+1) << ": ";
cin >> a[x].book_author[y].price;
}
}
} while (a[x].book_author[y].book_tittle == "NONE");
}
If you're running this from the debugger, when you try to access a null pointer, the program will crash and the debugger will snap on the exact line of code that is causing the problem.

Are you using a debugger? If so, can you try this and tell us what line the crash is occurring on?
I am using a debugger and it says line 929.
Are you sure? It doesn't look like your program is 929 lines long. Was it saying line 929 in some other file?
The problem was in line 29, where I was initializing the struct array. It should of been:
{{"NONE", "NONE", 0, "NONE", 0, "NONE", 0},
{"NONE", "NONE", 0, "NONE", 0, "NONE", 0},
{"NONE", "NONE", 0, "NONE", 0, "NONE", 0}};

since it should of been initialized 7 times per element.


Thank you for your help, when you mention the line, it helped me figure out what the problem was.
Topic archived. No new replies allowed.