Hi guys, I'm just starting to learn C and I've hit a wall with my current task. Any pointers or nudges in the right direction will be greatly appreciated.
Here's what I have to do:
"Write a program that uses an array of structures to hold contact information for your friends. The program should allow the user to enter as many friends as the user wants. Create functions to add or delete entries in the phone book and to print valid phone book entries. Do not display phone book entries that are invalid or NULL (0). You can assume that all people have unique names. Make sure you allocate and free memory as necessary."
Aaaaaaaaaaand here's what I have thus far:
Code:
#include <stdio.h>
#include <string.h>
int i;
int number_of_entries;
typedef struct{
char first [15];
char last [15];
char phone [15];
}phonebook;
main (){
phonebook entry[50];
int response;
printf("\n\tPhonebook\n\n");
printf("(1)Add Friend\n");
printf("(2)Delete Friend\n");
printf("(3)Show Phone Book\n");
printf("Enter selection: ");
scanf("%d", &response);
switch (response){
case 1:
number_of_entries++;
printf("Enter First Name: ");
scanf("%s", entry[i].first);
printf("Enter Last Name: ");
scanf("%s", entry[i].last);
printf("Enter Phone Number: ");
scanf("%s", entry[i].phone);
return 0;
break;
case 2:
case 3:
for(i; i<number_of_entries; i++){
printf("%s, %s, %s", entry[i].last, entry[i].first, entry[i].phone); }
return 0;
break;
}
system("pause");
return 0;
}
I'm sure there are errors abound, so go easy on me. When it doesn't output random characters (my guess is thats its pointing to a random address), it simply prints out blank values with commas between them. I'm not really sure where to go from here :\
Thanks in advance.