strcpy:
#include
char *my_strcpy(char *dest,const char *src)
{
int i=0;
while(*(src+i)!='\0')
{
*(dest+i)=*(src+i);
i++;
}
*(dest+i) = 0;
}
int main()
{
char a[ ]="hello";
char b[10];
my_strcpy(b,a);
printf("b:%s\n",b);
return 0;
}
strstr:
#include
char *strstr(const char *haystack,const char *needle)
{
int i=0;
int k=0;
int temp=0;
while(*(haystack+i)!='\0')
{
if(*(haystack+i)==*(needle+k))
{
if(temp==0)
{
temp = i;
}
k++;
}
else
{
if(*(needle+k)=='\0')
{
printf("temp:%d\n",temp);
return haystack+temp;
}
k = 0;
temp = 0;
}
i++;
}
return 0;
}
int main()
{
char a[]="hello world";
char b[]="wor";
char *p=NULL;
p = strstr(a,b);
printf("*p:%s\n",p);
return 0;
}