编写strcpy(s,t,n)函数 ,将t中最多前n个字符复制到s中
#include <stdio.h>
void strcpy(char *s,char *t,int n);
main()
{
char t[]="hello";
char s[]="";
strcpy(s,t,2);
printf("result:%s",s);
system("pause");
}
void strcpy(char *s,char *t,int n)
{
int count;
count =0;
while((*s++ =*t++)&&(count <n))
count++;
}
执行的结果是:hello 为什么呢 count 的限制不起作用 怎么把t中元素都复制到s中了,哪里出了问题 ,请大家帮助解答一下
void strcpy(char *s,char *t,int n);
main()
{
char t[]="hello";
char s[]="";
strcpy(s,t,2);
printf("result:%s",s);
system("pause");
}
void strcpy(char *s,char *t,int n)
{
int count;
count =0;
while((*s++ =*t++)&&(count <n))
count++;
}
执行的结果是:hello 为什么呢 count 的限制不起作用 怎么把t中元素都复制到s中了,哪里出了问题 ,请大家帮助解答一下
...全文


