12345678910111213141516171819202122232425 |
- #include "str.h"
- #include "bool.h"
- #include <stdlib.h>
- int get_str_size(char *str) {
- int size = 0;
- for (char *s = str; *s != '\0'; s++)
- size++;
- return size;
- }
- char *get_middle(char *str, int start, int end, BOOL include) {
- int size;
- if (include)
- size = end - (--start);
- else
- size = end - start - 1;
- char *str2 = (char *)malloc(sizeof(char) * size + 1);
- if (!str2)
- return NULL;
- for (int i = 0; i < size; i++)
- str2[i] = str[start + i];
- str2[size] = 0;
- return str2;
- }
|