UGH!!! Still struggling with just getting the bugs out of what i have so far. I have not started on the sorting part of the assignment yet. Anyways, it appears im only storing the last entry and cannot figure out why. Other problems include, the "Unkown Command" coming up when its not needed, and "P" printing my one stored entry and 19 more blank cells. Anyone have any suggestions for these?
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//strcmp
//strcpy
int i;
void create_entry(struct entry *entries, int i); /* Create entry at index i */
void delete(void);
struct entry
{
char name[12];
char surname[12];
char number[12];
};
struct entry book[20];
void Createnew(void)
{
printf("Enter Name\n");
i=0;
scanf("%s", book[i].name);
printf("Enter Surname\n");
scanf("%s", book[i].surname);
printf("Enter Phone Number\n");
scanf("%s", book[i].number);
}
void delete()
{
printf("Enter index of entry to delete\n");
scanf("%i",&i);
if( i<0 || i>20)
printf("invalid Entry\n");
else
(book[i].name," ");
}
int main(void)
{
char a; /* command line input */
a=='z';
for(i=0; i<20; i++)
{
strcpy(book[i].name, " ");
strcpy(book[i].surname," ");
strcpy(book[i].number," ");
}
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);
if(a=='a')
{
Createnew();
}
else if(a=='d')
{
delete();
printf("Entry Deleted\n");
}
else if(a=='p')
for(book[i].name!=" ";i<20;i++)
{
printf("%s\n%s\n%s\n",book[i].name,book[i].surname,book[i].number);
}
else (a!='a' || a!='d' || a!='q' || a!='p' ||a!='z' ||a!='s' );
printf("unknown command\n");
/* if(a=='s')*/
}
printf("\nBye\n");
return 0;
}