#include <stdio.h>
#include <string.h>
#include <assert.h>
char *strcopy(char *str_dest , char *str_source) //指针函数
{
char *p;
assert ((str_dest != NULL) && (str_source != NULL));
p = str_dest;
while (*str_source != '\0')
{
*str_dest = *str_source;
str_source++;
str_dest++;
};
return p;
}
void main(void)
{
char *a="hello";
char b[10];
char *c;
#if 1
printf("1----a = %s\n",a);
char *(*function)(char *, char *); //函数指针,要注意了,函数指针类型要和需要调用的函数类型一样,否则会有警告
function = strcopy; //不必写地址符
c = (*function)(b , a); //函数直接写
// c = function(b , a);
printf ("b = %s\n", b);
if (c != NULL)
{
printf ("c = %s\n", c);
}
else
{
printf ("c is NULL pointer");
}
#endif
#if 0
c = strcopy(b , a);
printf ("b = %s , %x\n", b,b);
printf ("c = %s, %x\n", c,&c);
#endif
}