Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   [help] hoe i can remove name from telephone book program (http://www.go4expert.com/forums/help-hoe-i-remove-telephone-book-program-t24340/)

dor8 2Jan2011 13:29

[help] hoe i can remove name from telephone book program
 
I make telephone book program in 'c' language ..
the program need:
to add person with first an last name and phone num and write him to file(txt),
to serch name from file,
and Delete all details of someone from the list by writing the firt name and last name..
i dont know how to do the last function (delete), i hope thet someone can help me..
my program not so good but the function add and find wores..
this is the code:
...
Code:

struct person
{
char firstname[10];
char lastName [15];
char phonenumber[15];
char email[20];
};

 
person fillStruct (person &pr);
void copyToText (person prso[],int&in);
void find();
void erase (person prso[],int&in);

int in=0;
void main ()
{
person prso[30];
char menu;
cout<<"\t\t Phone Book\n";
cout<<" Menu: \n\n";

 
for (;1;)
{
Add Phone\n";
Delete phone book\n";
find Phone by name\n";
Quit\n";
cin >> menu;

 
switch (menu)
{
case 'A': copyToText(prso,in);
break;
case 'D' : erase ();
break;
case 'F': find();
break;
case 'Q' :
exit(2);
break;
default :
cout <<"wrong input.. enter new value\n";
continue;
}
}
}
person fillStruct (person &pr)
{
cout<<"write firts name: ";
cin>>pr.firstname;
cout<<"\nwrite last name: ";
cin>>pr.lastName;
cout<<"\nphone number: ";
cin>>pr.phonenumber;
return pr;
}
 
void copyToText(person *prso,int&in)
{
person pr;
fillStruct(pr);
strcpy(prso[in].firstname,pr.firstname);
strcpy(prso[in].lastName ,pr.lastName);
strcpy(prso[in].phonenumber,pr.phonenumber);

 
FILE* ofp;
ofp = fopen("c:\\in.txt", "a");
if (ofp == NULL)
{
printf("The file could not be opened\n");
}
fprintf (ofp, "%s %s %s\n", pr.firstname, pr.lastName, pr.phonenumber, in++;
fclose(ofp);
}
void find()
{
char ch[50],name[30],aaa[30];
int i,j,fss=0;
FILE* fp;
fp = fopen("c:\\in.txt", "r");
cout<<"Enter Name to find\n";
cin>>name;
i=0;
while(!feof(fp))
{

fgets(ch,50,fp)
i=0;while (ch[i] != '\0')
{
j=0;
strcpy(aaa,"");
while (ch[i++] != ' ')
{
aaa[j] = ch[i-1];
j++;
aaa[j]='\0';
}
if (strcmp(Deme,name) == 0)
{
fss=1;
break;
}
fscanf(fp,"%[^\n]\n",chi=0;
}

if(fss==1)
{
cout<<ch<<"\n";
fscanf(fp,"%[^\n]\n",ch);
continue;
}
else (fss==0);
{
fclose(fp);
}



All times are GMT +5.5. The time now is 03:15.