Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "dz4.h";
- #include<stdio.h>
- #include<stdlib.h>
- Element* citaj(Element *p, int n) {
- Element *novi, *stari;
- int i;
- for (i = 0; i < n; i++) {
- novi = calloc(sizeof(Element));
- printf("Naziv %d. elementa?", i + 1);
- novi->ime = ucitaj(novi->ime);
- printf("Cena %d. elementa?", i + 1);
- scanf("%lf", &novi->cena);
- getchar();
- novi->sledeci = NULL;
- if (p == NULL) {
- p = novi;
- }
- else stari->sledeci = novi;
- stari = novi;
- }
- return p;
- }
- char* ucitaj(char* p) {
- char c;
- int i = 0;
- char *pom;
- while ((c = getchar()) != '\n') {
- if (i % 10 == 0) {
- pom = realloc(p, (i + 10) * sizeof(char));
- if (pom == NULL) {
- printf("Neuspesna realokacija!\n");
- exit(1);
- }
- else p = pom;
- }
- p[i++] = c;
- }
- pom = realloc(p, (i + 1) * sizeof(char));
- if (pom == NULL) {
- printf("Neuspesna realokacija!\n");
- exit(1);
- }
- else p = pom;
- p[i] = '\0';
- return p;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement