Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define R 25
- struct complex
- {
- char imie[25];
- char nazwisko[25];
- long int numer;
- };
- struct complex * dodaj(struct complex * tab, int n)
- {
- struct complex * pomoc;
- struct complex new_elem;
- printf("Podaj imie nowego kontaktu\n");
- fgets(new_elem.imie, R, stdin);
- printf("Imie to ");
- puts(new_elem.imie);
- printf("\nPodaj nazwisko nowego kontaktu\n");
- fgets(new_elem.nazwisko, R, stdin);
- printf("Podaj numer nowego kontaktu ");
- scanf("%li", &new_elem.numer);
- int i;
- pomoc=malloc(sizeof(struct complex)*(n+1));
- for (i=0; i<n; i++)
- pomoc[i]=tab[i];
- pomoc[n]=new_elem;
- free(tab);
- return pomoc;
- }
- int main()
- {
- int ile_osob=0;
- struct complex * tab;
- int odp;
- int i;
- for (i=0; i<1; i=i)
- {
- int j;
- /*for (j=0; j<1000; j++)
- {
- if (tab[j]==NULL)
- {
- ile_osob = j;
- break;
- }
- }*/
- printf("Narazie jest %i elementow", ile_osob);
- printf("\nNiniejszy program ma sporo opcji:");
- printf(".\nJesli chcesz dodac nowa osobe do ksiazki - napisz 1");
- printf("\nJesli chcesz znalezc osobe o danym numerze telefonu - napisz 2");
- printf("\nJesli chcesz wyswietlic kontakt o znanym Ci indeksie - napisz 3");
- printf("\nJesli nie chcesz nic robic - napisz 0\n");
- scanf("%i", &odp);
- if (odp==1)
- tab=dodaj(tab, ile_osob+1);
- }
- free(tab);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement