Advertisement
Guest User

Untitled

a guest
May 26th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include "dz4.h";
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4.  
  5. Element* citaj(Element *p, int n) {
  6. Element *novi, *stari;
  7. int i;
  8. for (i = 0; i < n; i++) {
  9. novi = calloc(sizeof(Element));
  10. printf("Naziv %d. elementa?", i + 1);
  11. novi->ime = ucitaj(novi->ime);
  12. printf("Cena %d. elementa?", i + 1);
  13. scanf("%lf", &novi->cena);
  14. getchar();
  15. novi->sledeci = NULL;
  16.  
  17. if (p == NULL) {
  18. p = novi;
  19. }
  20. else stari->sledeci = novi;
  21. stari = novi;
  22.  
  23. }
  24. return p;
  25. }
  26.  
  27. char* ucitaj(char* p) {
  28. char c;
  29. int i = 0;
  30. char *pom;
  31.  
  32. while ((c = getchar()) != '\n') {
  33. if (i % 10 == 0) {
  34. pom = realloc(p, (i + 10) * sizeof(char));
  35. if (pom == NULL) {
  36. printf("Neuspesna realokacija!\n");
  37. exit(1);
  38. }
  39. else p = pom;
  40. }
  41. p[i++] = c;
  42. }
  43. pom = realloc(p, (i + 1) * sizeof(char));
  44. if (pom == NULL) {
  45. printf("Neuspesna realokacija!\n");
  46. exit(1);
  47. }
  48. else p = pom;
  49. p[i] = '\0';
  50. return p;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement