自定義字符串定長拷貝函數my_strncpy()

char * my_strncpy(char *dest,const char *ptr,int n)
{
    char *temp = dest;
    int i = 0;
    while(*ptr != '\0')
    {
        if(i == n)
        {
            break;
        }
        i++;
        *temp = *ptr;
        temp++;
        ptr++;
    }
    *temp = '\0';
    return dest;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章