Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #define R 25
  3.  
  4. struct complex
  5.     {
  6.         char imie[25];
  7.         char nazwisko[25];
  8.         long int numer;
  9.     };
  10.  
  11. struct complex * dodaj(struct complex * tab, int n)
  12.     {
  13.     struct complex * pomoc;
  14.     struct complex new_elem;
  15.     printf("Podaj imie nowego kontaktu\n");
  16.     fgets(new_elem.imie, R, stdin);
  17.     printf("Imie to ");
  18.     puts(new_elem.imie);
  19.     printf("\nPodaj nazwisko nowego kontaktu\n");
  20.     fgets(new_elem.nazwisko, R, stdin);
  21.     printf("Podaj numer nowego kontaktu ");
  22.     scanf("%li", &new_elem.numer);
  23.     int i;
  24.     pomoc=malloc(sizeof(struct complex)*(n+1));
  25.     for (i=0; i<n; i++)
  26.         pomoc[i]=tab[i];
  27.     pomoc[n]=new_elem;
  28.     free(tab);
  29.     return pomoc;
  30. }
  31.  
  32. int main()
  33. {
  34.     int ile_osob=0;
  35.     struct complex * tab;
  36.     int odp;
  37.     int i;
  38.     for (i=0; i<1; i=i)
  39.     {
  40.         int j;
  41.         /*for (j=0; j<1000; j++)
  42.         {
  43.             if (tab[j]==NULL)
  44.             {
  45.                 ile_osob = j;
  46.                 break;
  47.             }
  48.         }*/
  49.         printf("Narazie jest %i elementow", ile_osob);
  50.         printf("\nNiniejszy program ma sporo opcji:");
  51.         printf(".\nJesli chcesz dodac nowa osobe do ksiazki - napisz 1");
  52.         printf("\nJesli chcesz znalezc osobe o danym numerze telefonu - napisz 2");
  53.         printf("\nJesli chcesz wyswietlic kontakt o znanym Ci indeksie - napisz 3");
  54.         printf("\nJesli nie chcesz nic robic - napisz 0\n");
  55.         scanf("%i", &odp);
  56.         if (odp==1)
  57.             tab=dodaj(tab, ile_osob+1);
  58.     }
  59.     free(tab);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement