现在的位置: 首页 > 综合 > 正文

实现strcpy

2013年04月14日 ⁄ 综合 ⁄ 共 317字 ⁄ 字号 评论关闭
/*
 * author:lx
 * date: 2011-10-04
 * brief: strcpy
 */

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

void*
lx_strcpy( char *p, char *q )
{       
        char *address = q;

        for ( ; *p != '\0'; p++ )
        {
                assert( *q != '\0' );
                
                *q = *p;
                q++;
        }

        return address;
}

int
main( void )
{
        char p[20] = "hello world";
        char d[50] = "what why how and which where!";
        

        printf ( "%s\n", (char*)lx_strcpy( p, d ) );
}

  

抱歉!评论已关闭.