#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;
}