Advertisement
Guest User

Untitled

a guest
May 28th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <stdlib.h>
  2.  
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <conio.h>
  6. typedef struct
  7. {
  8. char nazwisko[20];
  9. int wiek;
  10. }TStudent;
  11. void dodaj(TStudent[],int* );
  12. void prezentuj(TStudent[],int );
  13. void prezentujNazwisko(TStudent[],int );
  14. int main()
  15. {
  16. TStudent Studenci[50];
  17. int n=0;
  18. char menu[]="MENU\n1)Dodaj rekord\n2)Prezentuj wszystkie\n3)Wyszukaj po nazwisku\n8)Koniec\n";
  19. char znak;
  20. do{
  21. system("cls");
  22. printf("%s",menu);
  23. znak=getchar();
  24. switch(znak)
  25. {
  26. case'1':case'd':case'D':dodaj(Studenci,&n);break;
  27. case'2':case'p':case'P':prezentuj(Studenci,n);break;
  28. case'3':case'n':case'N':prezentujNazwisko(Studenci,n);break;
  29. }
  30. }while(znak!='8'&& znak!='k'&& znak!='K');
  31. return 0;
  32. }
  33. void dodaj(TStudent stab[],int* wn)
  34. {
  35. system("cls");
  36. getchar();
  37. printf("Rekord nr %d\nPodaj nazwisko: ",(*wn)+1);
  38. gets(stab[*wn].nazwisko);
  39. printf("Podaj wiek: ");
  40. scanf("%d",&stab[*wn].wiek);
  41. getchar();
  42. (*wn)++;
  43. }
  44. //=============================================
  45. void prezentuj(TStudent stab[],int n)
  46. {
  47. int k=0;
  48. system("cls");
  49. getchar();
  50. for (k=0;k<n;k++)
  51. {
  52. printf("%d: %s\t%d\n",k+1,stab[k].nazwisko,stab[k].wiek);
  53. }
  54. printf("Naciśnij dowolny klawisz aby kontynuować...");
  55. getchar();
  56. }
  57. //==============================================
  58. void prezentujNazwisko(TStudent stab[],int n )
  59. {
  60. int k=0;
  61. char nazwisko[20];
  62. system("cls");
  63. getchar();
  64. printf("Podaj nazwisko do wyszukania: ");
  65. gets(nazwisko);
  66. for (k=0;k<n;k++)
  67. {
  68. if(strstr(stab[k].nazwisko,nazwisko)==stab[k].nazwisko)
  69. printf("%d: %s\t%d\n",k+1,stab[k].nazwisko,stab[k].wiek);
  70. }
  71. printf("Naciśnij dowolny klawisz aby kontynuować...");
  72. getchar();
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement