home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <conio.h>
- #include <ctype.h>
- #include <string.h>
-
- #define FILENAME "tk.dat"
-
- typedef struct {
- char nev[30];
- char szam[15];
- char cim[30];
- char reserved;
- } ADAT;
-
-
- FILE *datfile;
-
- void bill();
-
- void main(void)
- {
- char c;
- void uj ();
- void lista ();
- long keres ();
- void modosit ();
- int openfile(char *filename);
-
- clrscr();
- if (openfile(FILENAME))
- {
- do
- {
- clrscr();
- printf("Fomenu:\n");
- printf(
- "\n1 - uj szam"
- "\n2 - listazas"
- "\n3 - kereses"
- "\n4 - modositas"
- "\n0 - kilepes");
- switch(c=getch())
- {
- case '1' : uj(); break;
- case '2' : lista(); break;
- case '3' : keres(); break;
- case '4' : modosit(); break;
- case '0' : printf("\n\n C S A !"); break;
- } // switch
- fflush(datfile);
- } while(c!='0');
- fclose(datfile);
- }
- } // main
-
- int openfile(char *filename)
- {
- if ((datfile=fopen(filename,"r+"))==NULL)
- {
- printf("Az adatfile nem letzik, letrehozok egy masikat...");
- bill();
- if ((datfile=fopen(filename,"w"))==NULL)
- {
- printf("Nem tudom letrehozni az adatfile-t (lehet hogy CD-rol inditottal)");
- return(0);
- }
- fclose(datfile);
- datfile=fopen(filename,"r+");
- }
- return(1);
- }
-
- void uj()
- {
- ADAT rek;
-
- fseek(datfile,0,SEEK_END);
- do
- {
- clrscr();
- printf("Kerem az adatokat\n\n");
- printf("Nev : ");
- fflush(stdin);
- gets(rek.nev);
- printf("Telefonszam : ");
- fflush(stdin);
- gets(rek.szam);
- printf("Lakcim : ");
- fflush(stdin);
- gets(rek.cim);
- rek.reserved=0;
- fwrite(&rek, sizeof(ADAT), 1, datfile);
- printf("\n\nVan meg adat? (i/n) ");
- } while(tolower(getch())!='n');
- } // uj
-
- void lista()
- {
- ADAT rek;
- int y=2;
-
- clrscr();
- printf(" nev telefonszam Lakcim\n");
- fseek(datfile,0,SEEK_SET);
- fread(&rek,sizeof(ADAT),1,datfile);
- while(!feof(datfile))
- {
- gotoxy(1,y);
- printf("%s",rek.nev);
- gotoxy(40-strlen(rek.szam)/2,y);
- printf("%s",rek.szam);
- gotoxy(80-strlen(rek.cim),y);
- printf("%s",rek.cim);
- fread(&rek,sizeof(ADAT),1,datfile);
- if (y==24)
- {
- bill();
- clrscr();
- printf(" nev telefonszam Lakcim/n");
- y=2;
- } else y++;
- }
- bill();
- } // lista
-
- long keres()
- {
- ADAT rek;
- int nincs;
- long i;
- char string[30];
-
- clrscr();
- printf("Kerem a nevet! ");
- fflush(stdin);
- gets(string);
- nincs=1;
-
- clrscr();
- fseek(datfile,0,SEEK_SET);
- fread(&rek,sizeof(ADAT),1,datfile);
- for(i=0;!feof(datfile) && nincs;i++)
- {
- if(strcmp(string,rek.nev)==0)
- {
- printf("Nev: %s\n",rek.nev);
- printf("Telefonszam: %s\n",rek.szam);
- printf("Lakcim: %s\n",rek.cim);
- nincs=0;
- } // if
- fread(&rek,sizeof(ADAT),1,datfile);
- } // for
- if(nincs)
- {
- printf("\n Ilyen nevet nem talatam.");
- bill();
- return(-1);
- }
- bill();
- return(i-1);
- } // kereses
-
- void modosit()
- {
- ADAT rek;
- long poz;
-
- clrscr();
- fflush(stdin);
- if ((poz=keres())!=-1)
- {
- poz*=sizeof(ADAT);
- printf("Kerem az uj nevet:\n");
- fflush(stdin);
- gets(rek.nev);
- printf("Kerem az uj szamot:\n");
- fflush(stdin);
- gets(rek.szam);
- printf("Kerem az uj cimet:\n");
- fflush(stdin);
- gets(rek.cim);
- rek.reserved=0;
- fseek(datfile, poz, SEEK_SET);
- fwrite(&rek, sizeof(ADAT), 1, datfile);
- printf("modositas megtortent");
- bill();
- }
- } // modositas
-
- void bill()
- {
- int x,y;
-
- x=wherex();
- y=wherey();
- gotoxy(1,25);
- printf("nyomj meg egy gombot....");
- getch();
- gotoxy(1,25);
- clreol();
- gotoxy(x,y);
- } // bill
-