开发者

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:

charFilenameAndPath=strtok(filename,".");
memcpy=(charFilename,charFilenameAndPath, sizeof(charFilenameAndPath));

and the compiler is spitting out this:

uTrackSpheres.cpp:176: error: assignment o开发者_开发技巧f 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


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 *. So, you are copying sizeof(char *) bytes to charFilename, you probably want strlen(charFilenameAndPath)+1 bytes instead (or you can use strcpy()). In any case, you should make sure that strtok() didn't return NULL and that charFilename has enough space.


memcpy is followed by a = and should not be. The error message says you are trying to assign a new value to the symbol memcpy, which isn't what you want to do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜