I Have created a Contact manager that stores contacts along with other information. I used a fixed size array, and need help changing program into a linked list. I also need help creating a search function. This function would let the user search the contacts by name, phone, address, etc. How would i get the function to search each list.
My program code is:
CODE
/* In this program we create a contact manager to manage three total
contacts, by student ID. Includes phone number GPA and Hours.*/
#include <stdio.h>
enum kind {GPA, HOURS} kind;
struct student{
union grade {
int hours;
double gpa;} grade;
int kind;
int id;
struct phone{
int area;
int pre;
int suf;} phone;
};
int main (int argc, char **argv){
int entry, i;
struct student stu[3];
char gh;
int num = 0;
do{
printf("[1] Enter a new Contact \n");
printf("[2] Display the Contacts \n");
printf("[3] Quit\n\n");
printf("Enter 1 - 3: ");
scanf("%i", &entry);
switch(entry){
case 1:
printf("Enter a Student ID number:\n900");
scanf("%i", &stu[num].id);
printf("[G] Enter GPA:\n");
printf("[H] Enter number of completed Hours\n");
scanf(" %c", &gh);
switch(gh){
case 'G':
stu[num].kind = GPA;
printf("GPA: ");
scanf(" %lf", &stu[num].grade.gpa);
break;
case 'H':
stu[num].kind = HOURS;
printf("Hours: ");
scanf(" %i", &stu[num].grade.hours);
break;
default:
printf("Incorrect entry\n");
}
printf("Enter the phone number (###) ###-####\n");
scanf(" (%i) %i-%i", &stu[num].phone.area, &stu[num].phone.pre, &stu[num].phone.suf);
num++;
break;
case 2:
for(i = 0; i<num; i++){
printf("ID: 900%i\n", stu[i].id);
if(stu[i].kind == GPA){
printf("GPA: %lf\n", stu[i].grade.gpa);
}
else if(stu[i].kind == HOURS){
printf("Hours: %i\n", stu[i].grade.hours);
}
printf("Phone: (%i) %i-%i\n", stu[i].phone.area, stu[i].phone.pre, stu[i].phone.suf);
}
break;
case 3:
printf("Thank You for using MyContactManager\n");
break;
default:
printf("Entry not acceptable\n");
}
} while(entry < 3);
return (0);
}
Any help greatly Appreciated. Thanks!