求教一道简单的题目
将字符串s2中的前m个字符存到字符数组s1中,并在结尾加上一个‘\0’。不能使用系统提供的strcpy函数。
程序代码:/*******************************************************************************
将字符串s2中的前m个字符存到字符数组s1中,并在结尾加上一个‘\0’。
不能使用系统提供的strcpy函数。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
水平有限,谨作参考。
*******************************************************************************/
#include<stdio.h>
#include<string.h>
#define N 1000
int main(void)
{
char s1[N];
char s2[N];
int i,m;
printf("input s2[]:\n");
gets(s2);
printf("input m:\n");
scanf("%d",&m);
if(strlen(s2)>=m)
{
for(i=0;i<m;i++)
s1[i]=s2[i];
s1[m]='\0';
puts(s1);
}
else printf("S1数组没有足够的长度。\n");
return 0;
getch();
}









