ghy19980814 2017-05-21 10:13 采纳率: 83.3%
浏览 738

C语言编译中返回指针问题

错误代码:
#include
char 指针*strcpy(char , char);
int main(void)
{
char a[20], b[60] = "there is a boat on the lake.";
printf("%s\n", strcpy(a, b));
return 0;
}
char 指针*strcpy(char s, char *t)
{
while(*s++ = *t++)
;
return (s);
}
正确代码:
#include
char *strcpy(char *, char
);
int main(void)
{
char a[20],b[60]="there is a boat on the lake.";
printf("%s\n", strcpy(a, b));
return 0;
}
char *strcpy(char *s, char *t)
{
char *m;
m=s;
while(*s++=*t++)
;
return (m);
}
问下为什么这样改就对了?

  • 写回答

2条回答 默认 最新

  • 关注

    char是一个字节,char*是地址,就这么简单的区别啊。还有哪里有问题?

    评论

报告相同问题?