fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <malloc.h>
  4. #include <ctype.h>
  5.  
  6. typedef struct Node {
  7. char word[50];
  8. struct Node *next;
  9. } Node;
  10.  
  11. Node *head,
  12. *head2;
  13.  
  14. char end[3] = "?!.", word[50];
  15.  
  16. int k = 0;
  17.  
  18. char ch;
  19.  
  20. int main(int argc, char const *argv[]) {
  21.  
  22. do
  23. {
  24. scanf("%c", &ch);
  25.  
  26. if(!isalpha(ch)) {
  27.  
  28. if( k ) {
  29.  
  30. Node *new_node = (Node*)malloc(sizeof(Node));
  31. strcpy(new_node->word, word);
  32. new_node->next = NULL;
  33.  
  34. if(head == NULL) {
  35.  
  36. head = new_node;
  37.  
  38. head2 = new_node;
  39.  
  40. } else {
  41.  
  42. if(strcmp(head->word, new_node->word) > 0) {
  43.  
  44. new_node->next = head;
  45.  
  46. head = new_node;
  47.  
  48. } else {
  49.  
  50. Node *aux = head;
  51.  
  52. while(aux->next && strcmp(aux->next->word, new_node->word) < 0) {
  53.  
  54. aux = aux->next;
  55. }
  56.  
  57. if(aux->next) {
  58.  
  59. new_node->next = aux->next;
  60.  
  61. aux->next = new_node;
  62.  
  63. } else {
  64.  
  65. aux->next = new_node;
  66. }
  67.  
  68. }
  69. }
  70.  
  71. k = 0;
  72. }
  73.  
  74. } else {
  75.  
  76. word[k++] = toupper(ch); word[k] = '\0';
  77.  
  78. }
  79.  
  80. } while(!strrchr(end, ch));
  81.  
  82. while(head) {
  83.  
  84. printf("%s ", head->word);
  85.  
  86. head = head->next;
  87. }
  88. return 0;
  89. }
  90.  
Success #stdin #stdout 0s 5516KB
stdin
statescu$adrian#@yahoo#com#dumitru1978manager!
stdout
ADRIAN COM DUMITRU MANAGER STATESCU YAHOO