<file_sep>#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "base.h"
#include "record.h"
// Function: print_all_records()
// Input: record - array of Records; this may contain empty elements in the middle
// Output: none
// - Leave a brief information about the function
/*void print_all_records(Participant participants[]){
	// TODO: Modify this function as you need
 
}*/

void create_pcp(linkedList *my_list,Participant *pcp,int *number_to_add)
{
  char flat;
  
  //Participant* kpcp;
  while(flat!='Q'){

     printf("Choose input methods or option to quit (K-keyboard, D-data file, Q-quit) ");
     scanf(" %c",&flat);
  
     if(flat == 'K')
     {
        add_pcp_from_k(pcp);
        (*number_to_add)++;
        create_new_node(my_list, pcp);
     }
      
    else if (flat == 'D')
     {
        add_pcp_from_d(my_list,pcp);
        (*number_to_add)++;
        //create_new_node(my_list, pcp);
        
     }
    
     else if (flat == 'Q')
     {
       break;
     }

     else{
       printf("You enetered the invalid option.");
       continue;
     }

    
        
  }

  //return (*number_to_add);

}

void add_pcp_from_k(Participant *pcp)
{ 
  char buffer[20];

  printf("create a new pcp data from a keyboard\n");
  printf("Enter the name \n(c.p. name format; if name is <NAME>, Enter like this->Kim_You_Jin) : ");
  scanf("%s",buffer);
  strncpy(pcp->name,buffer,sizeof(buffer));
  printf("Enter the phone number : ");
  scanf("%s",buffer);
  strncpy(pcp->phone_num,buffer,sizeof(buffer));
  printf("Enter the age : ");
  scanf("%d",&pcp->age);
  printf("Enter the name of high school : ");
  scanf("%s", buffer);
  strncpy(pcp->n_highsch,buffer,sizeof(buffer));
  printf("Enter the number of group : ");
  scanf(" %d",&pcp->gr_num);

  printf("The below infromaiton is added!\n");
  printf("%s\n%s\n%d\n%s\n%d\n",pcp->name,pcp->phone_num,pcp->age,pcp->n_highsch,pcp->gr_num);
  
   
}

void add_pcp_from_d(linkedList *my_list,Participant* pcp)
{
  char filename[10];
  char buffer[20];
  int i=0;
  printf("Enter the file name : ");
  scanf("%s",filename);

  FILE * fp= fopen(filename,"rt");
  if(fp==NULL){
    puts("Fail to open the file!");
  }

  else{

    while(!feof(fp)){
    
      fscanf(fp,"%s\n%s\n%d\n%s\n%d",pcp->name,pcp->phone_num,&pcp->age,pcp->n_highsch,&pcp->gr_num);
    
      i++;
    }
    
    printf("The below infromaiton is added!\n");
    printf("%s\n%s\n%d\n%s\n%d\n",pcp->name,pcp->phone_num,pcp->age,pcp->n_highsch,pcp->gr_num);

    create_new_node(my_list, pcp);
    fclose(fp);
  }
  
}

void create_new_node(linkedList *my_list,Participant *tpcp)
{
  node *new_node = (node *)malloc(sizeof(node));
  new_node->pcp = *tpcp;
  new_node->link=NULL;

  if(my_list->head == NULL && my_list->tail == NULL)
      my_list->head = my_list->tail = new_node;
  else
  {
    my_list->tail->link = new_node;
    my_list -> tail = new_node;
  }
}





void print_nodes(linkedList *my_list)
{
  char flat;
  char buffer;
  int o=0;
    printf("A- It prints out all participants,\n");
    printf("B- It only prints out the participant of the name you entered\n");
    printf("C- It only prints out the participant of the phone number you enetered\n");
    printf("D- It only prints out the participants of the age you entered\n"); 
    printf("E- It only prints out the participants of the name for high school you entered\n");
    printf("F- It only prints out the participant of the group number you enetered\n");
    printf("Q - if you want to quit, enter Q.\n");

  while(flat!='Q'){
    if(o>0){
       buffer =getchar();
    }
   
    printf("Choose the print condition you want : ");

    scanf("%c",&flat);

     if(flat == 'A')
     {
       print_all_nodes(my_list);
     }
     else if(flat == 'B')
     {
       print_name_nodes(my_list); 
     }
     else if(flat == 'C')
     {
        print_phone_num_nodes(my_list);
     }
       
     else if(flat == 'D')
     {
        print_age_nodes(my_list);
     }
        
     else if(flat == 'E')
     {
        print_school_nodes(my_list);
     }
        
     else if(flat == 'F')
     {
        print_group_num_nodes(my_list);
     }
        
     else if(flat == 'Q')
     {
        break;
     }
        
     else{
       printf("You enetered the invalid option.");
       continue;
     }
       
        
        
  }


}

void print_all_nodes(linkedList *my_list)
{
  node *p = my_list->head;
  int k = 0;
  printf("All prints out the list of participants\n");
  while(p!=NULL)
  {
    printf("=======================================\n");
      printf("=================No.%d==================\n",++k);
      printf("\tName : %s\n\tPhone_number : %s\n\tAge :  %d\n\tHigh School : %s\n\tGroup Number : %d\n",p->pcp.name,p->pcp.phone_num,p->pcp.age,p->pcp.n_highsch,p->pcp.gr_num);
   p=p->link;
  }
}


void print_name_nodes(linkedList *my_list)
{

   node *p;
   char yw[20];
   int k = 0;
   printf("Enter the name of the participant you want: ");
   scanf("%s",yw);
  
   for(p=my_list->head; p!=NULL; p=p->link)
   {
    if(!strncmp(p->pcp.name,yw,sizeof(yw)))
    {
      printf("=======================================\n");
      printf("=================No.%d==================\n",++k);
      printf("\tName : %s\n\tPhone_number : %s\n\tAge :  %d\n\tHigh School : %s\n\tGroup Number : %d\n",p->pcp.name,p->pcp.phone_num,p->pcp.age,p->pcp.n_highsch,p->pcp.gr_num);
    }

   }
  
}
void print_phone_num_nodes(linkedList *my_list)
{
   node *p;
   char yw[20];
   int k = 0;
   printf("Enter the phone number of the participant you want: ");
   scanf("%s",yw);

   for(p=my_list->head; p!=NULL; p=p->link)
   {
    if(!strncmp(p->pcp.phone_num,yw,sizeof(yw)))
    {
      printf("=======================================\n");
      printf("=================No.%d==================\n",++k);
      printf("\tName : %s\n\tPhone_number : %s\n\tAge :  %d\n\tHigh School : %s\n\tGroup Number : %d\n",p->pcp.name,p->pcp.phone_num,p->pcp.age,p->pcp.n_highsch,p->pcp.gr_num);
    }

   }
 
}


void print_age_nodes(linkedList *my_list)
{
   node *p;
   int num_yw=0;
   int k = 0;
   printf("Enter the age of the participant you want: ");
   scanf("%d",&num_yw);

   for(p=my_list->head; p!=NULL; p=p->link)
   {
    if(p->pcp.age == num_yw){
      printf("=======================================\n");
      printf("=================No.%d==================\n",++k);
      printf("\tName : %s\n\tPhone_number : %s\n\tAge :  %d\n\tHigh School : %s\n\tGroup Number : %d\n",p->pcp.name,p->pcp.phone_num,p->pcp.age,p->pcp.n_highsch,p->pcp.gr_num);
    }

   }

  

}


void print_school_nodes(linkedList *my_list)
{
   node *p;
   char yw[20];
   int k = 0;
   printf("Enter the school name of the participant you want: ");
   scanf("%s",yw);

   for(p=my_list->head; p!=NULL; p=p->link)
   {
    if(!strncmp(p->pcp.n_highsch,yw,sizeof(yw)))
    {
      printf("=======================================\n");
      printf("=================No.%d==================\n",++k);
      printf("\tName : %s\n\tPhone_number : %s\n\tAge :  %d\n\tHigh School : %s\n\tGroup Number : %d\n",p->pcp.name,p->pcp.phone_num,p->pcp.age,p->pcp.n_highsch,p->pcp.gr_num);
    }

   }
}


void print_group_num_nodes(linkedList *my_list)
{
  node *p;
  int num_yw=0;
  int k=0;
  printf("Enter the group number you want: ");
  scanf("%d",&num_yw);

  for(p=my_list->head; p!=NULL; p=p->link)
  {  
    if(p->pcp.gr_num == num_yw){
      printf("=======================================\n");
      printf("=================No.%d==================\n",++k);
      printf("\tName : %s\n\tPhone_number : %s\n\tAge :  %d\n\tHigh School : %s\n\tGroup Number : %d\n",p->pcp.name,p->pcp.phone_num,p->pcp.age,p->pcp.n_highsch,p->pcp.gr_num);
    }
      
    

  }
}

void export_entire_data_in_report(linkedList *my_list)
{

  char filename[20];
  node *p;
  int k=1;

  printf("We will export the entire data in a report format.\n");
  printf("Please keep the below rule of naming the file.\n");
  printf("1. Files should be named consistently.\n");
  printf("2. Use capitals and underscores instead of periods or spaces or slashes.\n");
  printf("3. Avoid special characters or spaces in a file name.\n");

  printf("Enter the file name you want to make : ");
  scanf("%s",filename);

  FILE *fp= fopen(filename,"wt");
  
  fprintf(fp,"=======================================\n");
  fprintf(fp,"========The Report Of Paricipant=======\n");
  fprintf(fp,"=======================================\n");
  for(p=my_list->head; p!=NULL; p=p->link)
  {
    fprintf(fp,"=================No.%d==================\n",k++);
    //name
    fprintf(fp,"\tName : %s\n",p->pcp.name);
    //phone_num
    fprintf(fp,"\tPhone Number : %s\n",p->pcp.phone_num);
    //age
    fprintf(fp,"\tAge : %d\n",p->pcp.age);
    //high school name
    fprintf(fp,"\tHigh school : %s\n",p->pcp.n_highsch);
    //group number
    fprintf(fp,"\tGroup Number : %d\n",p->pcp.gr_num);
    fprintf(fp,"=======================================\n");
  }
  
  fclose(fp);

}

void read_entire_data_from_file(linkedList *my_list)
{
  char filename[25];
  Participant buffer_pcp;
  printf("We will read the entire data in the list of participants from the file you want.\n");

  printf("Enter the file name you want to read : ");
  scanf("%s",filename);
  FILE * fp= fopen(filename,"rt");

  if(fp==NULL){
    printf("Fail to read the file!");
  }

  while(!feof(fp)){

    fscanf(fp,"%s\n%s\n%d\n%s\n%d\n",buffer_pcp.name,buffer_pcp.phone_num,&buffer_pcp.age,buffer_pcp.n_highsch,&buffer_pcp.gr_num);

    printf("%s\n%s\n%d\n%s\n%d\n",buffer_pcp.name,buffer_pcp.phone_num,buffer_pcp.age,buffer_pcp.n_highsch,buffer_pcp.gr_num);
    
  
  }
  
  fclose(fp);
    
}


void write_entire_data_to_file(linkedList *my_list)
{
  char filename[25];
  node *p;
  
  printf("We will write the entire data in the list of participants.\n");
  
  printf("Please keep the below rule of naming the file.\n");
  printf("1. Files should be named consistently.\n");
  printf("2. Use capitals and underscores instead of periods or spaces or slashes.\n");
  printf("3. Avoid special characters or spaces in a file name.\n");
  printf("Enter the file name you want to make : ");
  scanf("%s",filename);
  FILE * fp= fopen(filename,"wt");

  for(p=my_list->head; p!=NULL; p=p->link)
  {
    
    fprintf(fp,"%s\n%s\n%d\n%s\n%d\n",p->pcp.name,p->pcp.phone_num,p->pcp.age,p->pcp.n_highsch,p->pcp.gr_num);
    

  }
  
  fclose(fp);

}

void find_node_to_update(linkedList *my_list)
{
  char tname[20];
  node *p;
  printf("We will update the speific information of the participants you want.\n");
  printf("Enter the name of participant you want to update the specific information without space. replace space with '_'.: ");
  scanf("%s",tname);
  getchar();
  for(p=my_list->head; p!=NULL;p=p->link){
    if(!strncmp(p->pcp.name,tname,sizeof(tname)))
    {
      update_the_node(my_list,&p->pcp);
      //printf(" Update! Check the below data : )\n");
     // printf("\tName : %s\n\tPhone_number : %s\n\tAge :  %d\n\tHigh School : %s\n\tGroup Number : %d\n",p->pcp.name,p->pcp.phone_num,p->pcp.age,p->pcp.n_highsch,p->pcp.gr_num);
    }
  }


}

void update_the_node(linkedList *my_list,Participant *pcp)
{
   char flat;
   char tname[20];
   char buffer[20];
   int buffer_num;
  

       
       while(flat!='Q')
       {
         printf("A- Update the name\n");
         printf("B- Update the phone number\n");
         printf("C- Update the age\n");
         printf("D- Update the name of high school\n");
         printf("E- Update the number of group\n");
         printf("Q- Quit\n");
        
    
         printf("Enter the option you want: ");
         scanf("%c",&flat);
         
         if(flat=='A'){
           printf("Enter the new name to update without space. Replace space with '_' : ");
           scanf("%s",buffer);
           getchar();
           strcpy(pcp->name, buffer);
           print_update_data(pcp);
         }

         else if(flat=='B'){
           printf("Enter the new phone number to update and keep the format=XXX-XXXX-XXXX : ");
           scanf("%s",buffer);
           getchar();
           strcpy(pcp->phone_num,buffer);
           print_update_data(pcp);
         }

         else if(flat=='C'){
           printf("Enter the new age to update");
           scanf("%d",&buffer_num);
           getchar();
           pcp->age = buffer_num;
           print_update_data(pcp);
         }

         else if(flat=='D'){
           printf("Enter the new name of the high school without space. Replace space with '_'.");
           scanf("%s",buffer);
           getchar();
           strcpy(pcp->n_highsch,buffer);
           print_update_data(pcp);
         }
           
         else if(flat=='E'){
           printf("Enter the new group number to update");
           scanf("%d",&buffer_num);
           getchar();
           pcp->gr_num = buffer_num;
           print_update_data(pcp);
         }

         else if(flat=='Q'){
           break;
         }
     
        }
         
       
     
   
   

}

void print_update_data(Participant *pcp)
{
  printf(" Update! Check the below data : )\n");
      printf("\tName : %s\n\tPhone_number : %s\n\tAge :  %d\n\tHigh School : %s\n\tGroup Number : %d\n",pcp->name,pcp->phone_num,pcp->age,pcp->n_highsch,pcp->gr_num);
}

void find_node_to_delete(linkedList *my_list)
{
  char tname[20];
  node *p;
  printf("We will delete the information of the participants you want.\n");
  printf("Enter the name of participant you want to delete without space. replace space with '_'.: ");
  scanf("%s",tname);
  getchar();
  for(p=my_list->head; p!=NULL;p=p->link){
    if(!strncmp(p->pcp.name,tname,sizeof(tname)))
    {
      delete_the_node(my_list,&p->pcp);
      printf(" Delete! Print to see if it has been deleted.\n");
      print_name_nodes(my_list);
    }
    else{
      printf("Participant information with the name you entered does not exist.");
      break;
    }

  }
  


}

void delete_the_node(linkedList *my_list,Participant *pcp)
{
  strcpy(pcp->name, "\0");
  strcpy(pcp->phone_num, "\0");
  pcp->age = 0;
  strcpy(pcp->n_highsch, "\0");
  pcp->gr_num = 0;

}
<file_sep>#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "base.h"
#include "extra.h"
#include "record.h"



// function prototypes
void input_handler(char input[], linkedList *my_list,Participant* pcp,int * number_to_add);
void show_menu();

// main function
int main(){

	Participant pcp;
  linkedList *my_list = (linkedList *)malloc(sizeof(linkedList));
  my_list->head = NULL;
  my_list->tail = NULL;
  int number_to_add=0;
  int i=0;
  char c;
	char user_input[2] = "";
	while(strcmp(user_input, "99") != 0){
    if(i>0){
      c=getchar();
    }
    
		show_menu();
		printf("\nSelect a menu> ");
		fgets(user_input, 2, stdin);
		input_handler(user_input,my_list, &pcp,&number_to_add);
    i++;
	}

	return 0;
}


// Function: input_handler()
// Input: record - array of Records; this may contain empty elements in the middle
// Output: none
// - Handles the user input and invokes functions that correspond to the user input
void input_handler(char input[], linkedList *my_list,Participant* pcp,int * number_to_add){

	// TODO: Modify this function as you need

	if(!strcmp(input, "1"))
		create_pcp(my_list,pcp,number_to_add);
  else if(!strcmp(input, "2"))
    print_nodes(my_list);	
  else if(!strcmp(input, "3"))
		export_entire_data_in_report(my_list);
	else if(!strcmp(input, "4"))
		read_entire_data_from_file(my_list);
  else if(!strcmp(input, "5"))
		write_entire_data_to_file(my_list);
  else if(!strcmp(input, "6"))
		find_node_to_update(my_list);
  else if(!strcmp(input, "7"))
		find_node_to_delete(my_list);
  else if(!strcmp(input, "8"))
		advanced_search(my_list);
	else if(!strcmp(input, "99"))
		printf("Terminating... bye!\n"); 
    ;// Quit - no operation (an empty statement with a semi-colon)*/
	//else
//		printf("Unknown menu: %s \n\n", input);
}



// Function: show_menu()
// Input: none
// Output: none
// - prints out the main menu
void show_menu(){

	// TODO: Modify this function as you need

	printf("******************************\n");
	printf(" In G-IMPACT of Handong, the List of participants Management System(LMS) \n");
	printf("******************************\n");
	printf(" 1. create a new participants\n");
	printf(" 2. Print participants in the way you want\n");
	printf(" 3. Export the entire data in a report\n");
	printf(" 4. Read the entire data from the file you want\n");
  printf(" 5. Write the entire data to the file you want\n");
  printf(" 6. Update the data of the participant you want\n");
  printf(" 7. Delete the data of the participant you want\n");
  printf(" 8. advanced search\n");
  printf(" 99. Quit");
}
<file_sep>a.out: main.o base.o extra.o
	gcc -o a.out main.o base.o extra.o
main.o: base.h extra.h record.h main.c
	gcc -c -o main.o main.c
base.o : base.h base.c
	gcc -c -o base.o base.c
extra.o: extra.h extra.c
	gcc -c -o extra.o extra.c
clean:
	rm a.out main.o base.o extras.o

<file_sep>#ifndef _BASE_H_
#define _BASE_H_
#include <stdlib.h>
#include "record.h"

// function prototypes
//void print_all_records(Participant[]);
//void register_pcp(Participant participants[]);
//void ld_data(Participant participants[],char * filename);
void create_pcp(linkedList *my_list,Participant* pcp, int* number_to_add);
void add_pcp_from_k(Participant* pcp);
void add_pcp_from_d(linkedList *my_list,Participant* pcp);
void create_new_node(linkedList *my_list,Participant* tpcp);
void print_all_nodes(linkedList *my_list);
void print_name_nodes(linkedList *my_list);
void print_phone_num_nodes(linkedList *my_list);
void print_age_nodes(linkedList *my_list);
void print_school_nodes(linkedList *my_list);
void print_group_num_nodes(linkedList *my_list);
void print_nodes(linkedList *my_list);
void export_entire_data_in_report(linkedList *my_list);
void read_entire_data_from_file(linkedList *my_list);
void write_entire_data_to_file(linkedList *my_list);
void find_node_to_update(linkedList *my_list);
void update_the_node(linkedList *my_list, Participant *pcp);
void print_update_data(Participant *pcp);
void find_node_to_delete(linkedList *my_list);
void delete_the_node(linkedList *my_list,Participant *pcp);





#endif
<file_sep>#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "extra.h"
#include "record.h"

void advanced_search(linkedList *my_list) {
	node *p;
  	int group_num;
  	int age_up;
  	int k = 0;
  	printf("Enter the group number you want : ");
  	scanf("%d", &group_num);
  	printf("Enter more than age you want : ");
  	scanf("%d", &age_up);
  	
  	for(p=my_list->head; p!=NULL; p=p->link) {
    	if(p->pcp.gr_num == group_num && p->pcp.age >= age_up){
      		printf("=======================================\n");
      		printf("=================No.%d==================\n",++k);
      		printf("\tName : %s\n\tPhone_number : %s\n\tAge :  %d\n\tHigh School : %s\n\tGroup Number : %d\n",p->pcp.name,p->pcp.phone_num,p->pcp.age,p->pcp.n_highsch,p->pcp.gr_num);
    	}
    }
}<file_sep>#ifndef _RECORD_H_
#define _RECORD_H_

// type defition
typedef struct participant{

	// TODO: define your own structure type here
  char name[30]; // the name of the participant
  char phone_num[20]; // the phone number of the participant
  int age; // the age of the participant
  char n_highsch[30]; // the name of the particiapant’s highschool
  int gr_num;// the number of the group to which the participants belong

} Participant;


typedef struct node
{
  Participant pcp;
  struct node * link;

}node;

typedef struct linkedList
{
  node *head, *tail;

}linkedList;

#endif

<file_sep>
#ifndef _EXTRAS_H_
#define _EXTRAS_H_
#include <stdlib.h>
#include "record.h"

void advanced_search(linkedList *my_list);

#endif


<file_sep># the-List-of-participants-Management-System


             
             
             
## Information


       
       
### The subject     


####  -	In G-IMPACT of Handong, the List of participants Management System(LMS)      


            
            
### The purpose       


####  -	In G-IMPACT, the participants list is fixed finally the day before the event. Thus, the day before G-IMPACT, there are many fluctuations in the list. We need LMS to reflect the list fluctuation.      


####  -	The efficient sorting program of participants list is essential for safety management of all and G-IMPACT program operation.        


          
        
        
### How the complete system could be used     


####  -	Not only G-IMPACT, we can also use LMS in other event such as HanST, Handong English Camp etc.    


####  -	Regardless the scale of the event, we always can manage the participants list efficiently.    



                 
                 
                 
## Implementation    


         
         
### Create    


####  - create a new data of the participants list from a file    


####  - create a new data of the participants list from the standard input    


       
       
### Read    


####  - print a record, , multiple or all records to the standard output according to the specifed condition the user choose 


####  - read or write the data of the participants list from/to the file system    


####  - export the all data file of the participants in a report format as text file    


         
         
### Update   


####  - update the data of the participant the user want and choose    


      
      
### Delete   


####  - delete the data of the participant the user want


