6-10 使用函數實現字符串部分復制 (20分)


6-10 使用函數實現字符串部分復制 (20分)
 

本題要求編寫函數,將輸入字符串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; } /* 你的代碼將被嵌在這里 */ 
 

輸入樣例:

7
happy new year
 

輸出樣例:

new year



void strmcpy( char *t, int m, char *s )
{
 int i=0;
 int count=0;
 for(i=m-1;t[i]!='\0';i++)
 {
  
  s[count++]=t[i];
 }
 s[count]='\0';
 
 
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM