标签:gets title ++ stdio.h desc get span pac unsigned
1 #include<stdio.h> 2 #include<string.h> 3 #define MAXLEN 100 4 #define MAXNUM 2 5 6 void print(unsigned char uclen,unsigned char* pcArr) 7 { 8 for(unsigned char uci = 0;uci < uclen;uci++) 9 { 10 printf("%c",*pcArr); 11 pcArr++; 12 } 13 if(uclen < 8) 14 { 15 for(unsigned char uci = 0;uci < 8-uclen;uci++) 16 { 17 printf("0"); 18 } 19 } 20 printf("\n"); 21 return; 22 } 23 24 void printArr(unsigned char uclen,unsigned char* pcArr) 25 { 26 if(uclen <= 8) 27 { 28 print(uclen,pcArr); 29 } 30 else 31 { 32 print(8,pcArr); 33 uclen -= 8; 34 pcArr += 8; 35 printArr(uclen,pcArr); 36 } 37 return; 38 } 39 40 41 int main() 42 { 43 unsigned char uci; 44 unsigned char uclen; 45 unsigned char szArr[MAXLEN]; 46 szArr[0] = ‘\0‘; 47 for(uci = 0;uci < MAXNUM;uci++) 48 { 49 fgets(szArr,MAXLEN,stdin); 50 uclen = strlen(szArr); 51 szArr[--uclen] = ‘\0‘; 52 printArr(uclen,szArr); 53 } 54 return 0; 55 }
?连续输入字符串,请按长度为8拆分每个字符串后输出到新的字符串数组;
?长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。
连续输入字符串(输入2次,每个字符串长度小于100)
输出到长度为8的新字符串数组
abc 123456789
abc00000 12345678 90000000
标签:gets title ++ stdio.h desc get span pac unsigned
原文地址:http://www.cnblogs.com/ailx10/p/6287303.html