Hi, I'm writing a HR style program. The user is presented with a list of options to add employees details and sort them in various ways, simple stuff.
Now I'm trying to populate the 'PERSON' structure in the program below. However I keep getting the error message: 'The memory could not be written' - Being a raw beginner I'm finding it hard to get my head around the syntax for using a structure in this context. Any ideas on where I'm going wrong?
Code:#include <stdlib.h> #include <stdio.h> int get_selection (); void main_menu (int selection); void add_emp (struct PERSON aa []); void disp_emp (struct PERSON aa []); struct PERSON { char name [31]; }; void main () { int selection = 0; struct PERSON aa [2]; selection = get_selection (); main_menu (selection); add_emp ( aa ); disp_emp ( aa ); getch(); } int get_selection () { int selection = 0; printf ("1.Display all employees\n2.Add an employee"); printf ("\nEnter choice: "); do { scanf ("%d" , &selection); if ((selection < 1) || (selection > 2)) { printf ("Invalid"); } }while((selection < 1) || (selection > 2)); return (selection); } void main_menu (int selection , struct PERSON aa []) { do { switch (selection) { case 1 : disp_emp ( aa ); break; case 2 : add_emp ( aa ); break; case 3 : printf ("Exiting. Goodbye"); break; } }while (selection != 3); } void add_emp (struct PERSON aa []) { int i = 0; printf ("Enter name: \n"); for (i = 0; i < 2; i++) { gets (aa[i].name); } } void disp_emp (struct PERSON aa []) { int i = 0; for (i = 0; i < 2; i++) { printf ("%s\n" , aa[i].name); } }