The first input two integers m, n, representing the number of rows and length Request output, short length of a string into n long, more than enough to fill 0, newline continue output Such as input: 2, 8 1234567812345678123 Asd
O 12345678 12345678 12300000
A little code can't write the Int main () { Int m;//store the input string of the total number of rows Int n=8;//storage of fixed length int len; Int a rest; Int row; Int count; Char STR [100].//store the input string Char \ [100] [100].
For (int I=0; i <100; I++) For (int j=0; J & lt; 100; J++) { \ [I] [j]='\ 0'; //STR [I] [j]='\ 0'; //puts (temp [I]); }
Scanf_s (" % d ", & amp; M); Printf_s (" please input string \ n "); For (int I=0; i { Char c; int j=0; Scanf_s (" % s ", STR); /* while ((c=getchar ())! ) ='\ n'{ STR [I] [j++]=c; } getchar(); */ } //int index=0; //for (int j=0; J & lt; m; J++) //{ [j]//len=strlen (STR); //row=len/n; //if (row)//if the length more than fixed length //{ ////count=n - 1; //rest=len % n; //for (int k=0; K & lt; The row. K++) //{ //for (int I=0; i //{ //strncpy_s (temp [index], 1, & amp; STR [k] [I], n); //index++; //I=I + n. //} // // //} //for (int I=0; i //{ //puts (temp [I]); //} // //} // //
//}
}
CodePudding user response:
Use first row=len/n; Calculate how many full line, then output the full line in turn, finally use the nLenLeft len=% n calculate how much is left characters, if not zero, the remaining characters copied to the output buffer, the length of the remaining with 0