题目描述
•连续输入字符串,请按长度为8拆分每一个字符串后输出到新的字符串数组;
•长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。
输入描述:
连续输入字符串(输入2次,每一个字符串长度小于100)
输出描述:
输出到长度为8的新字符串数组数组
解法(C语言版):ide
#include<stdio.h> #include<string.h> char *outputstr(char *in, char *out) { int i; for(i = 0; i < 8; ++i) { if(in[i] != NULL) out[i] = in[i]; else out[i] = '0'; } return out; } int main() { char instr[100] = {0}; char outstr[9] = {0}; while(gets(instr)) { char *p = instr; while(*p != '\0') { printf("%s\n", outputstr(p, outstr)); p += 8; } memset(instr, 0, 100); } return 0; }