Untitled


SUBMITTED BY: bitcoinsachen

DATE: Nov. 21, 2016, 9:35 p.m.

FORMAT: Text only

SIZE: 1.2 kB

HITS: 682

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "c.h"
  4. #include <string.h>
  5. typedef struct Element_s{
  6. char songtitle[256], interpreter[256];
  7. struct Element_s *next;
  8. } Element_t;
  9. void readFromkeyboard(Element_t *item){
  10. if(!item);
  11. fprintf(stdout, "Error");
  12. return;
  13. fprintf(stdout, "Welcher Song: ");
  14. scanf("%s", item->songtitle);
  15. while(getchar() != '\n'){}
  16. fprintf(stderr, "Welcher Interpeter: ");
  17. scanf("%s", item->interpreter);
  18. while(getchar()!='\n'){}
  19. }
  20. Element_t *allocateElement(){
  21. Element_t *new=0;
  22. if(!(new=malloc(sizeof(Element_t)))){
  23. fprintf(stderr, "Memory allocation error");
  24. exit(-1);
  25. }
  26. readFromkeyboard(new);
  27. new->next=0;
  28. return new;
  29. }
  30. Element_t *insertLast(Element_t *list){
  31. Element_t *new = allocateElement();
  32. if(!list)
  33. return new;
  34. Element_t *last=list;
  35. while(last->next)
  36. last = last->next;
  37. last->next = new;
  38. return list;
  39. }
  40. void freeList(Element_t **list){
  41. if(!list){
  42. fprintf(stderr, "Nullpointer in freelist");
  43. exit(-1);
  44. }
  45. Element_t *next;
  46. while(*list){
  47. next = list[0]->next;
  48. free(list[0]);
  49. list[0]=next;
  50. }
  51. list[0]=0;
  52. }
  53. void print_singleElement(Element_t *element)
  54. {
  55. if(element){
  56. fprintf(stdout, "---")
  57. }
  58. }

comments powered by Disqus