Advertisement
Void-voiD

Untitled

Dec 23rd, 2018
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct Elem {
  6. struct Elem *next;
  7. char *word;
  8. };
  9.  
  10. struct Elem *InitSingleLinkedList()
  11. {
  12. struct Elem *list = (struct Elem*)malloc(sizeof(struct Elem));
  13. list->next = NULL;
  14. list->word = "xex";
  15. return list;
  16. }
  17.  
  18. struct Elem *bsort(struct Elem *list)
  19. {
  20.  
  21. return list;
  22. }
  23.  
  24. int main()
  25. {
  26. char *cur = (char*)malloc(100000 * sizeof(char));
  27. struct Elem *l = InitSingleLinkedList();
  28. struct Elem *c = l;
  29. struct Elem *f;
  30. int n = 0, len, i;
  31. while (1) {
  32. scanf("%s", cur);
  33. len = (int)strlen(cur);
  34. if (len != 0) {
  35. struct Elem *now = (struct Elem*)malloc(sizeof(struct Elem));
  36. now->word = cur;
  37. c->next = now;
  38. c = now;
  39. n++;
  40. }
  41. else break;
  42. }
  43. c = l->next;
  44. for (i = 0; i < n; i++) {
  45. printf("%s ", c->word);
  46. c = c->next;
  47. }
  48. c = l->next;
  49. for (i = 0; i < n; i++) {
  50. f = c->next;
  51. free(c);
  52. c = f;
  53. }
  54. free(cur);
  55. free(l);
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement