Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. // Created by Темирхан Мамаев on 05/12/2019.
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <limits.h>
  7.  
  8. int find_sub(char *str, char fs){
  9. if (strchr(str, fs)) {
  10. return 1;
  11. }
  12. return 0;
  13. }
  14.  
  15. char **podstr_split(char **s, int size_arr, char* fs, char* ls){
  16. int n = 0;
  17. char **podstr_arr = malloc(sizeof(char*) * 5);
  18. char **ps = podstr_arr;
  19. for(char **str = s; str < s + size_arr; str++){
  20. char *q = *str, *p = *str;
  21. while((q = strstr(q, fs)) && (p = strstr(q, ls))){
  22. *ps = malloc(sizeof(char) * (p - q - 1));
  23. strncpy(*ps, (q + 2), (p - q - 2));
  24. *(*ps + (p - q - 2)) = '\0';
  25. ps++;
  26. n++;
  27. q++;
  28. if (n % 5 == 0) {
  29. podstr_arr = realloc(podstr_arr, sizeof(char*) * (n + 5));
  30. ps = podstr_arr + n;
  31. }
  32.  
  33. }
  34. }
  35. *(podstr_arr + n) = NULL;
  36. return podstr_arr;
  37. }
  38.  
  39. void vstav_char(char *s, char ps, char h){
  40. char *p = s, *q;
  41. while((p = strchr(p, h))){
  42. q = strchr(p, '\0');
  43. while(q > p){
  44. *(q + 1) = *q;
  45. q--;
  46. }
  47. *(p + 1) = ps;
  48. p++;
  49. }
  50. }
  51.  
  52.  
  53. int main(int argc, const char * argv[]) {
  54. FILE *f;
  55. char buf[80], **p = NULL, **str = NULL, **s, *p_max, **podstr;
  56. int n = 0;
  57. if (!(f = fopen("data.txt", "rb"))) {
  58. printf("file don't exist");
  59. return 1;
  60. }
  61. else{
  62. while (!feof(f)) {
  63. str = (char**)malloc(sizeof(char*) * 5);
  64. p = str;
  65. while (!feof(f)) {
  66. fgets(buf, 79, f);
  67. *p = (char*)malloc((strlen(buf) + 1) * sizeof(char));
  68. strcpy(*p, buf);
  69. p++;
  70. n++;
  71. if (n % 5 == 0) {
  72. str = (char**)realloc(str, sizeof(char*) * (n + 5));
  73. p = str + n;
  74. }
  75. }
  76. }
  77. }
  78. podstr = podstr_split(str, n, "[[", "]]");
  79. puts(p_max);
  80. for(s = str; s < str + n; s++){
  81. vstav_char(*s, '0', '1');
  82. puts(*s);
  83. free(*s);
  84. }
  85. printf("\n__________________________________\n\n");
  86. for(s = podstr; *s; s++){
  87. puts(*s);
  88. free(*s);
  89. }
  90. free(podstr);
  91. free(str);
  92. fclose(f);
  93. printf("\n");
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement