将一个字符串中的前n个字符复制到一个字符数组中去 不许使用strcpy函数

2025-08-11 07:25:32
推荐回答(1个)
回答1:

#include 

void copy_str( char *s, char *t, int n)
{
int i;
for( i=0;i *t++=*s++ ;
*t='\0' ;
}
int main()
{
char a[20]="hello world" , b[20] ;
copy_str( a, b, 5 );
printf("b=%s\n", b );
return 0;
}