Brand new member who wants help because their program is due and they're jammed up? I'm sure it has never happened before ever! To be fair I have been trying to get help from the instructor and other programmers and no one has been responding. Any how...
I'm relatively sure the problem is somewhere within the fillACat function and/or the dynamicCatArray. I'm pretty sure the problem is with the pointer/array * - but I have no idea how to fix it.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
typedef struct {
double weight;
char name [30];
short int neutered;
} CAT;
void fillACat (CAT *dynamicCatArray[], char *names[], int i);
CAT* makeACat () {
CAT* result;
result = malloc (sizeof (CAT));
return result;
}
main () {
char *names[6] = {"Fluffy", "Tigger", "Max", "Betty", "Cat-27" , "Jake"};
int i;
CAT** dynamicCatArray;
dynamicCatArray = calloc (5, sizeof (CAT*));
srand (time(NULL));
for (i = 0; i < 5; i++) {
fillACat (dynamicCatArray, names, i);
}
free (dynamicCatArray);
system ("pause");
}
void fillACat (CAT *dynamicCatArray[], char *names[], int i) {
int catName, catWeight, catNeutered;
catName = rand () % 6;
catWeight = rand () % 30;
catNeutered = rand () % 2;
strcpy (dynamicCatArray[i]->name, names[catName]);
dynamicCatArray[i]->neutered = catNeutered;
dynamicCatArray[i]->weight = catWeight;
}
Any help that anyone can offer would be appreciated. I apologize in advance for any rules I might be breaking. Thanks