Example outputs for the use of these functions are included
Example outputs for the use of these functions are included below.
add: Assignment5Array of Structs and Enum Types tudent inforrmation Please enter your selection: a: add a new student to the list s: search for a student on the list d: display list of students q: quit and save your list ai Please enter the student\'s information in the following format: Tom:M:1st:11211:2350.75 Student added to list successfully Please enter your selection: name gender standard:roll_number tuition fee a: add a new student to the list s search for a student on the 1ist d: display list of students q: quit and save your list Please enter the student\'s information in the following format: Jerry:M:1st :12321:2450.55 Student added to list successfully Please enter your selection: name gender:standard roll_number:tuition_fee a: add a new student to the list s: search for a student on the list d: display list of students q: quit and save you list ai Please enter the student\'s information in the following format: Elsa:F:3rd:1233:3450.65 Student added to list successfully Please enter your selection: name gender standard:roll_number tuition fee a: add a new student to the list s search for a student on the 1ist d: display list of students q quit and save your listSolution
Please find the code for load() , search() and add() funtions . Please add in comments if anything else needed
int add(char* name, char* genderValueString, char* standard, int roll_number, float tuition_fee, struct student* list)
{
int i = 0, ret = 0 ,j=0;
int flag = 0;
if((roll_number < 0) || !(name[0] >=65 && name[0] <=90) || !(isdigit(standard[0])) || (genderValueString[0] != \'M\' && genderValueString[0] != \'F\') ){
return 0;
}
if(count != 0){
while((i < count) && ((ret = strcmp(list[i].name,name)) < 0)){
i++;
}
if(ret == 0){
if(list[i].roll_number == roll_number)
return 0;
else
i++;
}
if(i != count){
for(j=i ; j < count ;j++){
list[j+1] = list[j];
}
}
}
strncpy(list[i].name,name,sizeof(list[i].name) - 1);
list[i].name[29] = \'\\0\';
if(!strncmp(genderValueString,\"F\",1)){
list[i].genderValue = female;
}
else{
list[i].genderValue = male;
}
strncpy(list[i].standard,standard,strlen(standard));
list[i].roll_number = roll_number;
list[i].tuition_fee = tuition_fee ;
count++;
return 1;
}
char* search(char* name, int roll_number, struct student* list)
{
int i =0;
for(i=0; i < count ;i++){
if( !(strcmp(name,list[i].name)) && (list[i].roll_number == roll_number))
return list[i].standard;
}
return NULL;
}
void load(char* fileName)
{
FILE* fp = fopen(fileName,\"r\");
char ch = \' \';
char gen[10] = {\'\\0\'};
char input[200] = {\'\\0\'};
int i = 0;
if(fp == NULL){
printf(\"Cannot open the file\ \");
return;
}
i = count;
while(ch != EOF ){
fscanf(fp,\"%[^\ ]\",input);
if(strlen(input) == 0)
break;
strcpy(list[i].name,strtok(input,\":\"));
strncpy(gen,strtok(NULL,\":\"),10);
if(gen[0] == \'M\')
list[i].genderValue = male;
else
list[i].genderValue = female;
strncpy(list[i].standard,strtok(NULL,\":\"),sizeof(list[i].standard) - 1);
list[i].roll_number = atoi(strtok(NULL,\":\"));
list[i].tuition_fee = atof(strtok(NULL,\":\"));
i++;
count++;
ch = fgetc(fp);
memset(input,0,sizeof(input));
}
}

