Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1.  
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h> //for strcpy
  6. #include <ctype.h> //for isdigit
  7.  
  8. void searchList(struct Node **it, char **name, char **adresse, int *plz);
  9.  
  10. struct Node{
  11.  
  12. char *name;
  13. char *adresse;
  14. int plz;
  15. struct Node *next;
  16. struct Node *prev;
  17. };
  18.  
  19. int main (){
  20.  
  21. struct Node n1;
  22. struct Node n2;
  23. struct Node n3;
  24. struct Node n4;
  25. struct Node n5;
  26. struct Node n6;
  27.  
  28. n1.name = calloc(25, sizeof(char));
  29. n1.adresse = calloc(40, sizeof(char));
  30.  
  31. strcpy(n1.name, "Eva Lackner");
  32. strcpy(n1.adresse, "Hans-Radl Straße 9");
  33. n1.plz = 1030;
  34.  
  35. n2.name = calloc(25, sizeof(char));
  36. n2.adresse = calloc(40, sizeof(char));
  37.  
  38. strcpy(n2.name, "Erwin Unterlechner");
  39. strcpy(n2.adresse, "Udo Jürgens Gasse 1");
  40. n2.plz = 4040;
  41.  
  42. n3.name = calloc(25, sizeof(char));
  43. n3.adresse = calloc(40, sizeof(char));
  44.  
  45. strcpy(n3.name, "Mariam Lauterbach");
  46. strcpy(n3.adresse, "Achingerstraße 44");
  47. n3.plz = 1200;
  48.  
  49. n4.name = calloc(25, sizeof(char));
  50. n4.adresse = calloc(40, sizeof(char));
  51.  
  52. strcpy(n4.name, "Gerhard-Yusuf Iremat");
  53. strcpy(n4.adresse, "Laudongasse 7");
  54. n4.plz = 1080;
  55.  
  56. n5.name = calloc(25, sizeof(char));
  57. n5.adresse = calloc(40, sizeof(char));
  58.  
  59. strcpy(n5.name, "Meliha Arndt");
  60. strcpy(n5.adresse, "Alsterstraße 5");
  61. n5.plz = 5070;
  62.  
  63. n6.name = calloc(25, sizeof(char));
  64. n6.adresse = calloc(40, sizeof(char));
  65.  
  66. strcpy(n6.name, "Bruno Alplechner");
  67. strcpy(n6.adresse, "Grüntorstraße 88");
  68. n6.plz = 1090;
  69.  
  70. struct Node *list = NULL;
  71.  
  72. list = &n1;
  73. n1.next = &n2;
  74. n1.prev = NULL;
  75.  
  76. n2.next = &n3;
  77. n2.prev = &n1;
  78.  
  79. n3.next = &n4;
  80. n3.prev = &n2;
  81.  
  82. n4.next = &n5;
  83. n4.prev = &n3;
  84.  
  85. n5.next = &n6;
  86. n5.prev = &n4;
  87.  
  88. n6.next = NULL;
  89. n6.prev = &n5;
  90.  
  91. printf("Alle Kontakte:\n");
  92.  
  93. struct Node *it = list;
  94. while (it != NULL){
  95. printf("%s, %s, %d\n", it->name, it->adresse, it->plz);
  96. it = it -> next;
  97. }
  98.  
  99. printf("\nWiener Kontakte:\n");
  100.  
  101. it = &n1;
  102. searchList(it, it->name, it->adresse, &plz);
  103.  
  104.  
  105. return EXIT_SUCCESS;
  106. }
  107.  
  108. void searchList(struct Node **it, char **name, char **adresse, int *plz){
  109.  
  110. while (it != NULL){
  111.  
  112. int first = *plz; //Find out the first digit
  113. // Remove last digit from number till only one digit is left
  114. while(first >= 10)
  115. {
  116. first = first / 10;
  117. }
  118.  
  119. if (first == 1){ //if first digit is 1
  120.  
  121. printf("%s, %s, %d\n", name, adresse, plz);
  122. it = it -> next;
  123. }
  124. else{
  125. it = it -> next;
  126. }
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement