#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
const int max=100;
struct
{
char isim[11];
char tel[15];
} kisi[max];
void ekle();
void ara();
void listele();
main()
{
char kr;
cout<<" Telefon Rehberi"<<endl;
cout<<"MENU"<<endl;
cout<<"a)isim ekle"<<endl;
cout<<"b)isim ara"<<endl;
cout<<"c)tüm liste"<<endl;
cout<<"d)kapat"<<endl;
kr=getch();
switch(kr)
{
case 'a':
clrscr();
ekle();
break;
case 'b':
clrscr();
ara();
break;
case 'c':
clrscr();
listele();
break;
case 'd':
clrscr();
return EXIT_SUCCESS;
default :
clrscr();
main();
}
return EXIT_FAILURE;
}
void ekle()
{
FILE *di;
int i=0;
char dene[26];
di=fopen("c:telReh.txt","a+");
fseek(di,0,0);
for(i=0;i<max;i++)
{
if(fread(dene,1,26,di)==NULL)
{
cout<<"isim: ";
cin>>kisi[i].isim;
fwrite(kisi[i].isim,1,11,di);
cout<<"tel. no: ";
cin>>kisi[i].tel;
fwrite(kisi[i].tel,1,15,di);
cout<<"İşlem tamam";
break;
}
if(i==max-1)
cout<<"Hafıza dolu!";
}
getch();
fclose(di);
clrscr();
main();
}
void ara()
{
FILE *di;
char gecici[11];
int i=0,n;
di=fopen("c:telReh.txt","a+");
fseek(di,0,0);
cout<<"isim:";
gets(gecici);
n=strlen(gecici);
clrscr();
for(i=0;i<max;i++)
{
fread(&kisi[i],1,26,di);
if(strncmp(kisi[i].isim,gecici,n)==0)
{
cout<<kisi[i].isim<<" : " ;
cout<<kisi[i].tel;
getch();
clrscr();
break;
}
if(i==max-1)
{
cout<<"Kayıt bulunamadı";
getch();
clrscr();
}
}
fclose(di);
main();
}
void listele()
{
FILE *di;
int i=0;
di=fopen("c:telReh.txt","r");
clrscr();
cout<<"***** Tum Liste ****"<<endl<<endl;
for(i=0;i<max;i++)
{
if(fread(&kisi[i],1,26,di))
cout<<i+1<<")"<<kisi[i].isim<<" : "<<kisi[i].tel<<endl<<endl;
if(kisi[i].isim[0]==NULL)
{
getch();
break;
}
if(i%10==0 && i!=0)
{
getch();
clrscr();
cout<<"Devam...."<<endl<<endl;
}
}
clrscr();
fclose(di);
main();
}