Back at it again, Most bugs kinda worked out. Update on the code
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//strcmp
void delete(void);
struct entry
{
char name[12];
char surname[12];
char number[12];
};
struct entry book[20];
int Createnew(int i)
{
printf("Entry Number %i \n",i);
printf("Enter Name\n");
scanf("%s", book[i].name);
printf("Enter Surname\n");
scanf("%s", book[i].surname);
printf("Enter Phone Number\n");
scanf("%s", book[i].number);
i++;
printf("%i\n",i);
return i;
}
void delete()
{
int i;
printf("Enter index of entry to delete\n");
scanf("%i",&i);
if( i<0 || i>20)
printf("invalid Entry\n");
else{
strcpy(book[i].name, " ");
strcpy(book[i].surname," ");
strcpy(book[i].number," ");}
}
void printfunct(num_entries)
{
int i;
i=num_entries;
for(i=0;i<20;i++)
printf("%s\n%s\n%s\n\n\n",book[i].name,book[i].surname,book[i].number);
}
int main(void)
{
int num_entries;
num_entries=0;
int i;
i=0;
char a; /* command line input */
a='z';
for(i=0; i<=num_entries; i++)
{
strcpy(book[i].name, " ");
strcpy(book[i].surname," ");
strcpy(book[i].number," ");
}
i=0;
while(a!='q')
{
printf(" Enter a command\n 'A' : Add an Entry \n 'D' : Delete an Entry\n 'S' : Sort Entries \n 'P' : Print the phone book\n 'Q' : Quit\n\n");
scanf("%c",&a);
printf("\n\n");
if(a=='a')
{
i=Createnew(i);
num_entries=i;
}
else if(a=='d')
{
delete();
printf("Entry Deleted\n");
}
else if(a=='p')
{
printfunct(num_entries);
}
else
printf("unknown command\n");
/* if(a=='s')*/
}
printf("\nGood Bye!!\n");
return 0;
}