program crashes when enter struct array element

My program will allow the user to input a enter data to fill an array of the struct animal. for some reason when ever the first element gets filled it crashes the program. I'm thinking it might be a issue with memory allocation but being fairly new to c++ i might be wrong. Thank you to all that read this post and offer help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <string>
using namespace std;

const int AMOUNT = 100;

struct animal {
	char animal_type;
	char animal_name;
	int animal_age;
	char animal_food;
};

void input(animal *);

int main() {
	animal *array[AMOUNT];
	
	input(array[AMOUNT]);
	
	return 0;
}

void input(animal* array) {
	int x;
	int animal_amount;

	cout << "How many animals are you inputing";
	cin >> animal_amount;
	
	for (x = 0; x < animal_amount; x++) {
		cout << "Enter a type of animal: ";
		cin >> array[x].animal_type;
		
		cout << "Enter the animals name: ";
		cin >> array[x].animal_name;
		
		cout << "Enter the animals age";
		cin >> array[x].animal_age;

		cout << "Enter what the animal eats";
		cin >> array[x].animal_food;
	}
}
You're passing array[AMOUNT] to your input function, you probably mean to pass array

The first means you want to pass an unallocated object that is 1 past the total capacity of your array.
Line 17: Array is an uninitialized pointer. No space is allocated for the array. Why is this a pointer?

Line 19: You're passing a single out of bounds element (array[100]). Simply pass array.

BTW, animal_type, animal_name and animal_food are single characters. You probably want to use string for these.
It works now thank you for the help.
Topic archived. No new replies allowed.