문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top