Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define BUFFER 1024
  6.  
  7. struct fill
  8. {
  9. char *string;
  10. struct fill *next_string
  11. }*start = NULL,
  12. *list;
  13.  
  14. void error(int num)
  15. {
  16. switch(num)
  17. {
  18. case 1:
  19. printf("Not enough space in buffer\n");
  20. break;
  21. case 2:
  22. printf ("Memory allocation error\n");
  23. break;
  24. }
  25. exit(1);
  26. }
  27.  
  28. void input(char c,char *buf)
  29. {
  30. int i=0;
  31. while ((c = getchar()) != EOF)
  32. {
  33. if (((c == ' ') || (c == '\n')) && (i != 0))
  34. {
  35. buf[i]='\0';
  36. break;
  37. }
  38. else
  39. {
  40. if ( ( ( c >= 'a' && c <= 'z' ) ) ||
  41. ( c >= 'A' && c <= 'Z' ) )
  42. {
  43. buf[i]=c;
  44. i++;
  45. }
  46. }
  47. }
  48. buf[i]='\0';
  49. }
  50.  
  51. char *creat_din(char *mas,char *buf)
  52. {
  53. int n = strlen(buf);
  54. mas = (char *)malloc((n+1)*sizeof(char));
  55. if (mas == NULL) error(2);
  56. strcpy(mas, buf);
  57. return mas;
  58. }
  59.  
  60. struct fill *use_struct (struct fill *list,char *mas)
  61. {
  62.  
  63. list = (struct fill*)malloc(sizeof(struct fill));
  64. if (list == NULL) error(2);
  65. list->string = mas;
  66. list->next_string = start;
  67. start = list;
  68. printf("%s\n",list->string);
  69. return list;
  70. }
  71.  
  72. void entry(struct fill *start, FILE *mine)
  73. {
  74. while (start!=NULL)
  75. {
  76. fputs(start->string, mine);
  77. fputc('\n', mine);
  78. free(start);
  79. start=start->next_string;
  80. }
  81. }
  82.  
  83. int main(/*int argc, char *argv[]*/)
  84. {
  85. FILE *mine;
  86. char c, buf[BUFFER];
  87. char *mas;
  88. struct fill *rofl;
  89.  
  90. // if (argc == 2)
  91. // {
  92. // printf("Invalid input data, try again");
  93. // exit(2);
  94. // }
  95.  
  96. // if ((mine = fopen(argv[1], "w")) == NULL)
  97. // perror(argv[1]);
  98.  
  99. printf("Enter strings\n");
  100. do
  101. {
  102. input(c,buf);
  103. if (buf[0] != '\0')
  104. {
  105. mas = creat_din(mas,buf);
  106. list = use_struct(list, mas);
  107. }
  108. }
  109. while (*buf != '\0');
  110. for (rofl = start ;rofl!=NULL;rofl=rofl->next_string)
  111. {
  112. printf("string %s\n",rofl->string);
  113. }
  114.  
  115.  
  116. //entry(start, mine);
  117. //fclose(mine);
  118. return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement