69,382
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* memcpy(char* dst, char* src);
void main()
{
char *b,*c;
char *a = NULL;
b="asdfddd";
c = memcpy(a,b);
printf("%s\n",c);
free(c);
}
char* memcpy(char* dst, char* src)
{
char *a,*b;
b = src;
int s = strlen(b);
dst = (char*)malloc(strlen(b)+1);
a= dst;
while(s--)
{
*a++=*b++;
//printf("%d",strlen(b));
}
//printf("%d\n",dst);
*a = '\0';// 加个这个语句就OK了
return dst;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* memcpy(char* dst, char* src);
void main()
{
char *b,*c;
char *a = NULL;
b="asdfddd";
c = memcpy(a,b);
printf("%s\n",c);
free(c);
}
char* memcpy(char* dst, char* src)
{
char *a,*b;
b = src;
int s = strlen(b);
dst = (char*)malloc(strlen(b)+1);
a= dst;
while(s--){
*a++=*b++;
//printf("%d",strlen(b));
}
//printf("%d\n",dst);
*a='\0';//加上这句!!!!!!!!!!!!!!!
return dst;
}