[英]trying to copy a char pointer using memcpy, getting an error
so I want to copy a char pointer, asked a friend and he said to use memcpy... so I am trying to do this: 所以我想复制一个char指针,问一个朋友,他说要用memcpy ......所以我试着这样做:
charFilenameAndPath=strtok(filename,".");
memcpy=(charFilename,charFilenameAndPath, sizeof(charFilenameAndPath));
and the compiler is spitting out this: 并且编译器正在吐出这个:
uTrackSpheres.cpp:176: error: assignment of function ‘void* memcpy(void*, const void*, size_t)’ uTrackSpheres.cpp:176: error: cannot convert ‘unsigned int’ to ‘void*(void*, const void*, size_t)throw ()’ in assignment
I also tried using strlen instead of sizeof 我也尝试使用strlen而不是sizeof
memcpy
is followed by a =
and should not be. memcpy
之后是a =
,不应该。 The error message says you are trying to assign a new value to the symbol memcpy
, which isn't what you want to do. 错误消息显示您正在尝试为符号
memcpy
分配新值,这不是您想要执行的操作。
In your second line: 在你的第二行:
memcpy=(charFilename,charFilenameAndPath, sizeof(charFilenameAndPath));
there is a spurious =
sign. 有一个寄生
=
标志。
Once you fix that, your call is not correct anyway. 一旦你解决了这个问题,你的电话就不正确了。
charFilenameAndPath
is the return value from strtok()
, so it must be a char *
. charFilenameAndPath
是strtok()
的返回值,因此它必须是char *
。 So, you are copying sizeof(char *)
bytes to charFilename
, you probably want strlen(charFilenameAndPath)+1
bytes instead (or you can use strcpy()
). 因此,您将
sizeof(char *)
字节复制到charFilename
,您可能需要strlen(charFilenameAndPath)+1
字节(或者您可以使用strcpy()
)。 In any case, you should make sure that strtok()
didn't return NULL
and that charFilename
has enough space. 在任何情况下,您应该确保
strtok()
没有返回NULL
并且charFilename
有足够的空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.