C语言指针——字符串做函数参数

字符串做函数参数,退化为指针

#define  _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//字符串做函数参数,退化为指针

//字符串copy,str1 拷贝到 str2;
int copy_str(char *from, char *to )
{
    int ret = 0;
    if (from == NULL || to == NULL)
    {
        ret = - 1;
        return ret;
    }
    printf("from:%s \n", from);
    char *tmpfrom = NULL;
    char *tmpto = NULL;
    tmpfrom = from;
    tmpto = to;
//form形参 形参to 的值 不停的在变化....
//不断的修改了myfrom和myto的指向
    while (*tmpto++ = *tmpfrom++) //*操作 和++的操作; ++ 优先级高 //  后置++,先 *to = *from;  再from++, to++
    {
        ; 
    }
    return ret;
}


int main()
{
    int ret = 0;
    char *from = "abcd";
    char to[100];
    copy_str(from, to);
    printf("to:%s \n", to);

    system("pause");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/a6taotao/article/details/80084885
今日推荐