题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
#include <stdio.h> #include <string.h> #include <stdlib.h> static void splitStr(char *str) { if (str == NULL) { return; } int len = strlen(str); if (len > 8) { char s1[9] ={0}; strncpy(s1, str, 8); printf("%s\n", s1); splitStr(str + 8); } else { char split[9] = {0}; memset(split, '0', 8); strncpy(split, str, len); printf("%s\n", split); } } int main() { char str[101]; while (scanf("%s", &str) != EOF) { splitStr(str); } return 0; }