本題要求編寫函數,将輸入字元串t中從第m個字元開始的全部字元複制到字元串s中。
函數接口定義:
void strmcpy( char *t, int m, char *s );
函數strmcpy将輸入字元串char *t中從第m個字元開始的全部字元複制到字元串char *s中。若m超過輸入字元串的長度,則結果字元串應為空串。
裁判測試程式樣例:
#include <stdio.h>
#define MAXN 20
void strmcpy( char *t, int m, char s );
void ReadString( char s[] ); / 由裁判實作,略去不表 */
int main()
{
char t[MAXN], s[MAXN];
int m;
scanf("%d\n", &m);
ReadString(t);
strmcpy( t, m, s );
printf("%s\n", s);
return 0;
void strmcpy( char *t, int m, char *s ){
int len = strlen(t), i;
if ( m > len)
s = NULL;
for ( i = m - 1; i < len; i++){
s[i - (m - 1)] = t[i];
}
}