tags:

views:

350

answers:

2

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  A: 

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.

Kevin Conner
+2  A: 

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.

Alok