I'm trying to make account system in C. I'm trying this way to make input to struct arrays.
struct account { // Account Structure
int id;
int money;
char *name[30];
};
account * accountarray[50];
int number;
void MakeAccount() {
int id;
int input_money;
char name[50];
printf("--Make Account--\n");
printf("Input ID : ");
scanf("%d", &id);
printf("Insert Money : ");
scanf("%d", &input_money);
printf("Your Name? : ");
scanf("%s", name);
accountarray[number++] = NULL; // I think there's a problem in this side
accountarray[number++]->id = id;
accountarray[number++]->money = input_money;
*accountarray[number++]->name = name;
}
It stops when i get input the values... I think 4 codes on under has problem.. is there a good way to make it better?
accounttype with an array of thirty pointer-to-char (not an array of char, an array of pointer-to-char) as a member, and a global array of fifty pointer-toaccount. In all of this only one thing actually has any of those pointers pointing to something, and it's a temporary (name). You repeated increment ofnumberbetween each field assignment looks terribly wrong as well.accountarray[number++] = NULL;followed byaccountarray[number++]->id = id;... This mistake (null pointer dereference) should be obvious if you're reading a book. Are you reading a book?