Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. struct osoby{
  4.     char imie[20];
  5.     char nazwisko[25];
  6.     int wiek;
  7. };
  8. int main(){
  9.     int z,i=0,j=0;
  10.     struct osoby *tab;
  11.     tab=(struct osoby*)malloc(sizeof(struct osoby));
  12.     while(1){
  13.         printf("Jesli dodac 1 \nJesli odczytac 2 \nJesli wyjsc 0 \n");
  14.         scanf("%d",&z);
  15.         if(z==0){
  16.             break;
  17.         }
  18.         switch (z){
  19.             case 1:{
  20.                 tab=(struct osoby*)realloc(tab,i*sizeof(struct osoby));
  21.                 printf("Podaj imie: \n");
  22.                 scanf("%s",tab[i].imie);
  23.                 printf("Podaj nazwisko: \n");
  24.                 scanf("%s",tab[i].nazwisko);
  25.                 printf("Podaj wiek: \n");
  26.                 scanf("%d",&tab[i].wiek);
  27.                 i++;
  28.                 break;
  29.             }
  30.             case 2:{
  31.                 printf("\n");
  32.                 for(j=0;j<i;j++){
  33.                     printf("%s %s %d \n",tab[j].imie,tab[j].nazwisko,tab[j].wiek);
  34.                 }
  35.                 printf("\n");
  36.                 break;
  37.             }
  38.         }
  39.     }
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement