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 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
Best Answer
In your second line:
there is a spurious
=
sign.Once you fix that, your call is not correct anyway.
charFilenameAndPath
is the return value fromstrtok()
, so it must be achar *
. So, you are copyingsizeof(char *)
bytes tocharFilename
, you probably wantstrlen(charFilenameAndPath)+1
bytes instead (or you can usestrcpy()
). In any case, you should make sure thatstrtok()
didn't returnNULL
and thatcharFilename
has enough space.