【发布时间】:2014-07-22 08:05:37
【问题描述】:
Practice.c
#include <stdio.h>
#include <string.h>
int main(void)
{
char srce[]="abcd fghi jklmn";
char dest[20];
strcpy(dest,sizeof(srce),srce);
printf("\n%s",dest);
return 0;
}
在编译时我明白了:
Practice.c: In function 'main':
Practice.c:9:3: warning: passing argument 2 of 'strcpy' makes pointer from integer
without a cast [enabled by default]
strcpy(dest,sizeof(srce),srce);
^
In file included from Practice.c:2:0:
c:\mingw\include\string.h:57:39: note: expected 'const char *' but argument is of
type 'unsigned int'
_CRTIMP char* __cdecl __MINGW_NOTHROW strcpy (char*, const char*);
^
Practice.c:9:3: error: too many arguments to function 'strcpy'
strcpy(dest,sizeof(srce),srce);
^
是我strcpy()的语法写错了,还是我的代码不正确?
链接到书籍和网页,以研究数组、字符串、指针和结构。
目前我正在使用Apress: Beginning C 5th Edition。
【问题讨论】:
-
错误信息很清楚,参数不匹配,仔细阅读。阅读
strcpy和strncpy的手册。 -
@VSP 我在答案中添加了教程链接。