누군가이 코드의 잘못된 점을 말해 줄 수 있습니까? 주요C++ 포인터 질문
는 :
이Book* test = new Book;
char* end = "HelloThere";
test->reverseCString(end);
char* Book::reverseCString(char* woot)
{
char* end = woot;
while (*end)
{
end++;
}
end--;
// Now we end is at the last letter
// and woot is at the first
// now we swap them
char temp;
while (woot < end)
{
temp = *woot;
*woot++ = *end; <--- Problem here during runtime.
*end-- = temp;
}
return woot;
}
문제가 있습니까? 어떤 종류의 문제? 오류 메시지 또는 추가 정보가 있습니까? –
이 함수를 어떻게 부르시겠습니까? woot도 쓰기 가능합니까? – Michael
또한 기술적으로 이것은 빈 문자열에서 호출 될 때 UB를가집니다. 배열의 시작 전에 하나의 포인터를 작성해도 다른 포인터와 비교할 필요는 없습니다. 나는 그것이 당신의 문제라고 생각합니다. –