Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include <conio.h>
- typedef struct
- {
- char nazwisko[20];
- int wiek;
- }TStudent;
- void dodaj(TStudent[],int* );
- void prezentuj(TStudent[],int );
- void prezentujNazwisko(TStudent[],int );
- int main()
- {
- TStudent Studenci[50];
- int n=0;
- char menu[]="MENU\n1)Dodaj rekord\n2)Prezentuj wszystkie\n3)Wyszukaj po nazwisku\n8)Koniec\n";
- char znak;
- do{
- system("cls");
- printf("%s",menu);
- znak=getchar();
- switch(znak)
- {
- case'1':case'd':case'D':dodaj(Studenci,&n);break;
- case'2':case'p':case'P':prezentuj(Studenci,n);break;
- case'3':case'n':case'N':prezentujNazwisko(Studenci,n);break;
- }
- }while(znak!='8'&& znak!='k'&& znak!='K');
- return 0;
- }
- void dodaj(TStudent stab[],int* wn)
- {
- system("cls");
- getchar();
- printf("Rekord nr %d\nPodaj nazwisko: ",(*wn)+1);
- gets(stab[*wn].nazwisko);
- printf("Podaj wiek: ");
- scanf("%d",&stab[*wn].wiek);
- getchar();
- (*wn)++;
- }
- //=============================================
- void prezentuj(TStudent stab[],int n)
- {
- int k=0;
- system("cls");
- getchar();
- for (k=0;k<n;k++)
- {
- printf("%d: %s\t%d\n",k+1,stab[k].nazwisko,stab[k].wiek);
- }
- printf("Naciśnij dowolny klawisz aby kontynuować...");
- getchar();
- }
- //==============================================
- void prezentujNazwisko(TStudent stab[],int n )
- {
- int k=0;
- char nazwisko[20];
- system("cls");
- getchar();
- printf("Podaj nazwisko do wyszukania: ");
- gets(nazwisko);
- for (k=0;k<n;k++)
- {
- if(strstr(stab[k].nazwisko,nazwisko)==stab[k].nazwisko)
- printf("%d: %s\t%d\n",k+1,stab[k].nazwisko,stab[k].wiek);
- }
- printf("Naciśnij dowolny klawisz aby kontynuować...");
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement