Hello I'm newbie in C programming. Iwant to make a simple contact book that have add, delete, edit, and display function. 2 out of 4 i've done which is add and delete. So I need some help from all of you in edit and list function. Here is my function for add and delete. I refer this from acidburn code and changed it a little bit and i don't want to use ctype.h because not familiar with it yet.
void Add()
{
char opt1;
do
{
Contactbook = fopen("Contactbook.txt","a+");
printf("Enter his/her Name:\n");
scanf("%s", contactbook.name);
printf("Enter his/her Birthday:\n");
scanf("%s", contactbook.birthday);
printf("Enter his/her Handphone No:\n");
scanf("%s", contactbook.hp);
printf("Enter his/her Address:\n");
scanf("%s", contactbook.address);
printf("Enter his/her Occupation\n");
scanf("%s", contactbook.occupation);
fprintf(Contactbook, "%s %s %s %s %s\n", contactbook.name,
contactbook.birthday, contactbook.hp, contactbook.address,
contactbook.occupation);
fclose(Contactbook);
printf("To Continue using this program type Y/y");
scanf("%c", &opt1);
}
}
void Del()
{
char opt2;
char Tar [SIZE];
int match = 0;
temp = fopen("temp.txt", "w");
if((Contactbook = fopen("Contactbook.txt","r")) == NULL)
printf("----The file is empty----\n");
else
printf("Enter his/her name:");
gets(Tar);
while (!feof(Contactbook))
{
fscanf(Contactbook,"%s %s %s %s %s",
contactbook.name, contactbook.birthday, contactbook.hp,
contactbook.address, contactbook.occupation);
if(feof(Contactbook))
break;
if(strcmp(Tar, contactbook.name) !=0)
fprintf(temp,"%s %s %s %s %s\n", contactbook.name,
contactbook.birthday, contactbook.hp, contactbook.address,
contactbook.occupation);
else
{
match = 1;
}
if (!match)
{
printf("The name does not exist\n");
printf("or it might had been deleted\n");
}
fclose(Contactbook);
fclose(temp);
remove("Contactbook.txt");
rename("temp.txt","Contacbook.txt");
}
So i need some help on edit and list function. At 1st i think i want to use the same code as delete but change remove to rename but it can't be done that's way. So your helps are highly appreciated. Ok. Thanks