/* 13. Książka adresowa Program umożliwia dodanie i zapisanie w pliku danych: imię, nazwisko, numer identyfikacyjny, nr telefonu, nr telefonu komórkowego, dokładnych danych adresowych. Możliwe jest wyszukiwanie osób z uwzględnieniem imienia, nazwiska, nr telefonu, nr telefonu komórkowego lub adresu. */ //initializing the header files #include #include #include #include //defining the properties of the fields used in the program #define NAMES 50 #define IDNUM 20 #define PHONE 20 #define ADDRESS 80 #define TOWN 10 #define SIZE 500 //deklaracje funkcji void welcome_note(); void record(); void view(); void search(); void del_rec(); char info[SIZE]; //struktura struct addressbk { char name [NAMES] ; char sname [NAMES] ; char idnumber [IDNUM] ; char address [ADDRESS]; char town [TOWN]; char phone [PHONE]; char cellphone [PHONE]; char postcode [PHONE]; char country[TOWN]; char Target[NAMES]; } addressbk; //pliki uzywane przez program FILE *Records; FILE *rectemp; //glowna funkcja /****************************************************************************************************/ int main(void) { int choice=0; system("cls"); fflush(stdin); welcome_note(); printf("\nCo chcesz zrobic :"); scanf("%i",&choice); fflush(stdin); switch (choice) { case 1: { system("cls"); view(); break; } case 2: { system("cls"); record(); break; } case 3: { system("cls"); search(); break; } case 4: { system("cls"); del_rec(); break; } case 5: { system("cls"); break; } default: { printf("Prosze wybrac cyfre z zakresu 1-5\n"); system("pause"); system("cls"); main(); } } return 0; } /********************************************************************************************/ //funkcja wyswietla menu glowne void welcome_note() { printf("\n\tMENU GLOWNE\n\n"); printf(" 1 = PRZEJRZYJ WPISY\n"); printf(" 2 = DODAJ NOWY WPIS\n"); printf(" 3 = SZUKAJ WPISU\n"); printf(" 4 = USUN WPISY\n"); printf(" 5 = ZAKONCZ\n"); } /******************************************************************************************************/ //funkcja zapisujaca void record() { char choice2; printf("Dodaj nowy wpis"); do { //otwieram plik Records = fopen("Records.txt","a+"); printf("Podaj imie :"); fflush(stdin); scanf("%s",addressbk.name); printf("\nPodaj nazwisko"); fflush(stdin); scanf("%s",addressbk.sname); printf("\nNR identyfikacyjny:"); fflush(stdin); scanf("%s",addressbk.idnumber); printf("Podaj adres\n"); fflush(stdin); scanf("%s",addressbk.address); printf("\nPodaj miasto"); fflush(stdin); scanf("%s",addressbk.town); printf("\nPodaj Panstwo"); fflush(stdin); scanf("%s",addressbk.country); printf("\nPodaj Kod Pocztowy"); fflush(stdin); scanf("%s",addressbk.postcode); printf("\nEnter NR telefonu"); fflush(stdin); scanf("%s",addressbk.phone); printf("\nEnter NR telefonu komorkowego:"); fflush(stdin); scanf("%s",addressbk.cellphone); fprintf(Records,"%s %s %s %s %s %s %s %s %s \n",addressbk.name,addressbk.sname,addressbk.idnumber,addressbk.address,addressbk.town,addressbk.country,addressbk.postcode,addressbk.phone); fflush(stdin); fclose(Records); printf("Dodac nastepny? T/N \n"); scanf("%c",&choice2); fflush(stdin); if (choice2=='n'||choice2=='N') { system("cls"); main(); } }while(choice2=='t'||choice2=='T'); } /****************************************************************************************************************/ //przegladanie wpisow void view() { char choice3; printf("\n\tPrzegladaj wpis\n"); Records = fopen("Records.txt","r"); while(!feof(Records)) { fscanf(Records,"%s %s %s %s %s %s %s %s %s ",addressbk.name,addressbk.sname,addressbk.idnumber,addressbk.address,addressbk.town,addressbk.country,addressbk.postcode,addressbk.phone,addressbk.cellphone); printf("Imie: %s\n",addressbk.name); printf("Nazwisko: %s\n",addressbk.sname); printf("NR identyf: %s\n",addressbk.idnumber); printf("Adres : %s\n",addressbk.address); printf("Miasto: %s\n",addressbk.town); printf("Panstwo: %s\n",addressbk.country); printf("Kod pocztowy: %s\n",addressbk.postcode); printf("NR tel: %s\n",addressbk.phone); printf("NR tel kom.: %s\n",addressbk.cellphone); } fclose(Records); printf("\nSzukac wpis??(T/N)\n"); scanf("%c",&choice3); fflush(stdin); if (toupper(choice3)=='T') { search(); } else if(toupper(choice3)=='N') { fclose(Records); system("cls"); main(); } else { fclose(Records); system("cls"); } } /***********************************************************************************************/ //funkcja szukaj void search() { char Target[SIZE]; // int Found=0; if((Records=fopen("Records.txt","r"))==NULL) printf("BRAK WPISOW PLIK PUSTY!!!\n\n"); else { system("cls"); printf("\n\n"); printf("\t************** SZUKAJ ************"); printf("\n\n"); printf("\tPodaj tekst do odnalezienia:"); fflush(stdin); scanf("%s",Target); while(!feof(Records)&& Found==0) { fscanf(Records,"%s %s %s %s %s %s %s %s %s ",addressbk.name,addressbk.sname,addressbk.idnumber,addressbk.address,addressbk.town,addressbk.country,addressbk.postcode,addressbk.phone,addressbk.cellphone); if(strcmp(Target,addressbk.name)==0 || strcmp(Target,addressbk.sname)==0) Found=1; } if(Found) { printf("ZNALEZIONO:\n\n"); printf("1 FILE FOUND : \n\n\n"); printf("Imie: %s\n",addressbk.name); printf("Nazwisko: %s\n",addressbk.sname); printf("NR identyf: %s\n",addressbk.idnumber); printf("Adres : %s\n",addressbk.address); printf("Miasto: %s\n",addressbk.town); printf("Panstwo: %s\n",addressbk.country); printf("Kod pocztowy: %s\n",addressbk.postcode); printf("NR tel: %s\n",addressbk.phone); printf("NR tel kom.: %s\n",addressbk.cellphone); system("pause"); main(); } else if(!Found) { printf("NIE ZNALEZIONO\n"); system("pause"); main(); } fclose(Records); } } /***************************************************************************************************/ void del_rec() { //char name[NAMES]; char Target[SIZE]; int Found=0; system("cls"); printf("\n\tUSUN WPIS"); rectemp=fopen("rectemp.txt","w"); if((Records=fopen("Records.txt","r"))==NULL) printf("BRAK WPISOW W BAZIE!!!\n\n"); else{ printf("\n\n"); printf("\t***********USUN***********"); printf("\n\n"); printf("\tPodaj nazwe do usuniecia: "); fflush(stdin); gets(Target); while(!feof(Records)) { fscanf(Records,"%s %s %s %s %s %s %s %s %s ",addressbk.name,addressbk.sname,addressbk.idnumber,addressbk.address,addressbk.town,addressbk.country,addressbk.postcode,addressbk.phone,addressbk.cellphone); if(feof(Records)) break; if(strcmp(Target,addressbk.name)!=0) fprintf(rectemp,"%s %s %s %s %s %s %s %s %s \n",addressbk.name,addressbk.sname,addressbk.idnumber,addressbk.address,addressbk.town,addressbk.country,addressbk.postcode,addressbk.phone); else { Found=1; printf(".......FILE FOUND\n"); system("pause"); printf("Imie:%s\n",addressbk.name); printf("Nazwisko:%s\n",addressbk.sname); printf("NR ident:%s\n",addressbk.idnumber); printf("Adres : %s\n",addressbk.address); printf("Miasto: %s\n",addressbk.town); printf("Panstwo: %s\n",addressbk.country); printf("Kod pocztowy: %s\n",addressbk.postcode); printf("NR telefonu: %s\n",addressbk.phone); printf("NR telefonu kom.: %s\n",addressbk.cellphone); fflush(stdin); system("pause"); } } if (!Found) { printf("\tNIE ZNALEZIONO\n"); } printf("\tWpis USUNIETY!!\n"); fclose(Records); fclose(rectemp); remove("Records.txt"); rename("rectemp.txt","Records.txt"); main(); } } //}