Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- int main(void)
- {
- static char lbuf[1024];
- static char rbuf[1024];
- static char cbuf[1024];
- //const char *str = "testing between two spaces here ---> <--- ok";
- const char *str = "hello xyz world";
- size_t cursor_pos = 9;
- const size_t len = strlen(str);
- size_t split_pos = cursor_pos ? cursor_pos - 1 : 0;
- while (split_pos > 0 && !isspace(str[split_pos])) {
- --split_pos;
- }
- memcpy(lbuf, str, split_pos + 1);
- memcpy(rbuf, str + cursor_pos, len - cursor_pos);
- memcpy(cbuf, str + split_pos + 1, cursor_pos - split_pos);
- printf("%s\n", lbuf);
- printf("%s\n", rbuf);
- printf("%s\n", cbuf);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement