Void-voiD

Untitled

Dec 23rd, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 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(1000000 * sizeof(char));
  27. struct Elem *l = InitSingleLinkedList();
  28. struct Elem *c = l;
  29. struct Elem *f;
  30. char *a = (char*)malloc(1000 * sizeof(char));
  31. int n = 0, i, j = 0, len = 0;
  32. gets(cur);
  33. for (i = 0; i < (int)strlen(cur); i++) {
  34. if (cur[i] != 32) {
  35. a[j] = cur[i];
  36. j++;
  37. len++;
  38. }
  39. if (cur[i] == 32 && 0 != len) {
  40. len = 0;
  41. j = 0;
  42. struct Elem *now = (struct Elem *)malloc(sizeof(struct Elem));
  43. now->word = a;
  44. c->next = now;
  45. c = now;
  46. n++;
  47. }
  48. }
  49. c = l->next;
  50. for (i = 0; i < n; i++) {
  51. printf("%s ", c->word);
  52. c = c->next;
  53. }
  54. c = l->next;
  55. for (i = 0; i < n; i++) {
  56. f = c->next;
  57. free(c);
  58. c = f;
  59. }
  60. free(cur);
  61. free(l);
  62. free(a);
  63. return 0;
  64. }
Add Comment
Please, Sign In to add comment