字符串分隔
字符串分隔
http://www.nowcoder.com/questionTerminal/d9162298cb5a437aad722fccccaae8a7
c
#include <stdio.h> #include <string.h> int main(void) { char str[100] = {0}; while(gets(str)) { char dst[8] = {0}; char *p = str; int len = strlen(str); int n = len%8; for (int i = 0; i < len/8; i++) { strncpy(dst, p, 8); fwrite(dst, 1, 8, stdout); memset(dst, 0, sizeof(dst)); p += 8; printf("\n"); } if (n != 0) { strncpy(dst, p, n); for (int i = 0; i < (8-n); i++) { dst[n + i] = '0'; } fwrite(dst, 1, 8, stdout); printf("\n"); } } return 0; }