1

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

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.