Vous êtes sur la page 1sur 6

++c – ‫ספר טלפונים ב‬

this prgram was wirten by yossi bachar*/


the date:08/08/2000
the teacher:amit limony
the program was wirten on borland ver 5
the program have some error on it
error 1:it dosent save atomatcly
error 2:it has some problom with the modify fanction
/* error 3:ther is no hkpada on kelet all over the program
<include<stdio.h#
<include<conio.h#
<include<string.h#
<include<ctype.h#
<include<alloc.h#
<include<stdlib.h#
<include<dos.h#
define MAX_PH 100#
"define FILENAME "phonerec.txt#
******************************************************************************//
typedef struct kartis
{
struct
{
;[char FirstName[10
;[char LastName[10
;name}
struct
{
;[char Street[10
;[char number[4
;[char city[15
;address}
struct
{
;[char phone[10
;tel}
;struct kartis *next

;phone}
;phone *start
******************************************************************************//
;(void load(void
;(void modify(void
;(void removeall(void
;(void delone(const char *s
;(void global_adition(void
;(void addrecord(void
;(void writetofile(void
;(void DisplayList(void
;(void DisplayPhone(phone* ptr
;([[phone* findbyfirstname(const char pname
;(void main_menu(void
;(void load (void
******************************************************************************//
((void main
;int ok {
;[char pname[10
;phone *pointer
;start=NULL
;((load

{do
;((main_menu
;(fflush(stdin
;((ok =getchar
;(fflush(stdin
(switch (ok
{
;((case '1': global_adition
;break

;((case '2': DisplayList


;break

;((case '3': removeall


;break

;(case '4': remove(FILENAME


;break

;(".case '5': delone("Enter first name of person you wont to delete


;break

(case '6': if (start


;(":printf("Enter First Name{
;(gets(pname
;(pointer=findbyfirstname(pname
;(DisplayPhone(pointer
}
;((else} clrscr
;("printf ("There are no record to search
}
;break
;((case '7': modify
;break

;((case '8': writetofile


;break

(case 27 :if (start!=NULL


;((removeall
;((clrscr
;("printf("\nGood - Bye\n\n
;(exit(1
;break
;("default:printf("\nNo such option
}

;(while (ok !=27}


}
******************************************************************************//
this fanction is colling to the main menu after every opretion//

((void main_menu
{
;("***printf("\n\t\t\t*** PHONE - BOOK
;("printf("\n\t\t\t*** MAIN MENU ***\n
;("printf("\n\t*** please select one of the foloing options***\n\n
;("printf("1.Add a new record\n
;("printf("2.Display the Phone Book\n
;("printf("3.Delete all records\n
;("printf("4.Delete file\n
;("printf("5.Delete one record\n
;("printf("6.Serch by first name\n
;("printf("7.Modify\n
;("printf("8.Save\n
;("printf("Esc to exit\n
;("printf ("\nEnter your choice:\n
}
******************************************************************************//
this fanction is saving data to the file it tell as if it can open//
or cant writ from or to the file//

(void writetofile(void
{
;FILE *fp
;phone *p=start

(if((fp=fopen(FILENAME,"wb"((==NULL
{
;(printf("ERROR OPENING FILE %s\n",FILENAME
;(getch((; fflush(stdin
;(exit(2
}
(while(p
{
(if(fwrite(p,sizeof(phone(,1,fp(!=1
{
;(printf("ERROR WRITING TO FILE %s\n",FILENAME
;(getch((; fflush(stdin
;(exit(2
}
;p=p->next
}
;(fclose(fp
}
******************************************************************************//
this fanction job is to call addrecord fanction and ask the user if he//
wonts to add another one//
(void global_adition(void
{
;int ok
{do
;((addrecord

;("printf("\n\tMORE?->(yes/no(\n
;(((ok=tolower(getch
;(fflush(stdin
;('while(ok!='n}
}
******************************************************************************//
this fanction allow us to add some person to the phone book//

((void addrecord
{
;phone *ptr,*s,*f

;((ptr=(phone*(malloc(sizeof(phone
;(" :printf("\nEnter FirstName
;(gets(ptr->name.FirstName
;(" :printf("Enter LastName
;(gets(ptr->name.LastName
;(" :printf("Enter Street
;(gets(ptr->address.Street
;(printf("Enter %s 's street number: ",ptr->name.FirstName
;(gets(ptr->address.number
;(" :printf("Enter City
;(gets(ptr->address.city
;(printf("Enter %s 's phone number: ",ptr->name.FirstName
;(gets(ptr->tel.phone

;s=start
;f=start
(while(f != NULL && strcmp(f->name.FirstName,ptr->name.FirstName(<0
{
;s=f
;f=f->next
}
(if(s==start
{
;ptr-> next =start
; start=ptr
}
else
{
;ptr->next =s ->next
;s->next=ptr
}
}
******************************************************************************//
this fanction give us the option to show the user the person exist//
on his phone book//

(void DisplayList(void
{
;phone *p=start
(while(p
{
;((clrscr
;(DisplayPhone(p
;p=p->next
;("printf("\n\n\tPress the enter key\n\n
; ((getch
;((getchar
;(fflush(stdin
}
}

(void DisplayPhone(phone* ptr


{
;(printf("FirstName: %s\n",ptr->name.FirstName
;(printf("LastName: %s\n",ptr->name.LastName
;(printf("Street: %s\n",ptr->address.Street
;(printf("Street number: %s\n",ptr->address.number
;(printf("City: %s\n",ptr->address.city
;(printf("Phone number: %s\n",ptr->tel.phone
}
******************************************************************************//
this fanction allow the user to clean his phone book by deleting it//

((void removeall
{
;phone* temp=start,*ptr
(if(start
{
(while(temp
{
;ptr=temp
;temp=temp->next
;(free(ptr
}
(if(ptr
;(free(ptr
;start=ptr=NULL

}
}

******************************************************************************//
this fanction is deleting only one record at a time it searches the name//
by first name//
(void delone(const char *s
{
;phone *ptr,*temp=start,*temp1
;[char pname[10
;(printf("%s",s
;(gets(pname
ptr=findbyfirstname(pname(;//leyvar she mohkim
(if(!ptr
;("printf("There no such person.\n
else
{
(while(temp!=ptr
{
;temp1=temp
;temp=temp->next
}
;temp1->next=ptr->next
;(free(ptr
}
}
******************************************************************************//
this fanction help the user find his persons in the phone book//
it also needed in the delone fanction and modify fanction//

([[phone* findbyfirstname(const char pname


{
;phone* ptr=start,*q=start
(while( ptr!=NULL && strcmp(ptr->name.FirstName,pname(!=0
{
;q=ptr
;ptr=ptr->next
}
(if(!ptr
;(return(NULL
else
;(return(q
}
******************************************************************************//
this fanction ask for first name if it fined the name it delet the record//
and call fanction addrecord to enter a new one//
((void modify
{
;[char pname[10
;phone *ptr
;("puts("Enter First Name to modify the record
;(gets(pname(; fflush(stdin
;(ptr=findbyfirstname(pname
(if(ptr
{
;("delone("\n
;((addrecord
}
else
;(".puts("Person is not found
}
******************************************************************************//
this fanction open the file befor we start working with the phone book//

((void load
{
;FILE* fp
;phone *ptr, *ptr1
(if((fp=fopen(FILENAME,"r"((==NULL
{
;(printf("Unable opening. File %s is empty.\n",FILENAME
;("printf("\t\tPress enter to continue.\a
;((getch
;((getchar
;(fflush(stdin
}
else
{
((if(!feof(fp
{
;((start=ptr=(phone*(malloc(sizeof(phone
;(fread((void*(ptr,sizeof(phone(,1,fp
;ptr->next=0

((while(!feof(fp
{
;((ptr1=(phone*(malloc(sizeof(phone
;(fread((void*(ptr1,sizeof(phone(,1,fp
;if(feof(fp(( break
;ptr1->next=0
;ptr->next=ptr1
;ptr=ptr1

}
;(fclose(fp
}
}
}

.....‫גם עבודה זו נלקחה מהאתר‬


!‫ – מאגר העבודות הגדול בישראל‬Avodot.co.nr

Vous aimerez peut-être aussi