Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct Elem {
- struct Elem *next;
- char *word;
- };
- struct Elem *InitSingleLinkedList()
- {
- struct Elem *list = (struct Elem*)malloc(sizeof(struct Elem));
- list->next = NULL;
- list->word = "xex";
- return list;
- }
- struct Elem *bsort(struct Elem *list)
- {
- return list;
- }
- int main()
- {
- char *cur = (char*)malloc(1000000 * sizeof(char));
- struct Elem *l = InitSingleLinkedList();
- struct Elem *c = l;
- struct Elem *f;
- char *a = (char*)malloc(1000 * sizeof(char));
- int n = 0, i, j = 0, len = 0;
- gets(cur);
- for (i = 0; i < (int)strlen(cur); i++) {
- if (cur[i] != 32) {
- a[j] = cur[i];
- j++;
- len++;
- }
- if (cur[i] == 32 && 0 != len) {
- len = 0;
- j = 0;
- struct Elem *now = (struct Elem *)malloc(sizeof(struct Elem));
- now->word = a;
- c->next = now;
- c = now;
- n++;
- }
- }
- c = l->next;
- for (i = 0; i < n; i++) {
- printf("%s ", c->word);
- c = c->next;
- }
- c = l->next;
- for (i = 0; i < n; i++) {
- f = c->next;
- free(c);
- c = f;
- }
- free(cur);
- free(l);
- free(a);
- return 0;
- }
Add Comment
Please, Sign In to add comment