0

I've been looking for the thread re swapping values of two string pointers but I couldn't findit and I don't know if it has already been solved. Assuming it's still on the lines waiting, I think I've got the simple code to solve it:

#include <windows.h>

void swap(LPCTSTR*,LPCTSTR*);

int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
{
	char szBuf[1024];
	LPCTSTR ptr1 = "Pointer 1";
	LPCTSTR ptr2 = "Other pointer";
	wsprintf(szBuf, "This is the first order before calling swap():\n\nptr1: %s\nptr2: %s",
		ptr1, ptr2);
	MessageBox(0, szBuf, "swap demo", MB_ICONINFORMATION);
	swap(&ptr1, &ptr2);
	wsprintf(szBuf, "and after calling swap():\n\nptr1: %s\nptr2: %s", ptr1, ptr2);
	MessageBox(0, szBuf, "swap demo", MB_ICONINFORMATION);
	return 0;
}

void swap(LPCTSTR *ppstr1, LPCTSTR *ppstr2)
{
	LPCTSTR ptemp = *ppstr1;
	*ppstr1 = *ppstr2;
	*ppstr2 = ptemp;
}

If there's an abvious reason why I came too late, think it's maybe because I don't have my own internet connection.

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Dream2code
0

Kurt Kubing,
>I don't know if it has already been solved.
It doesn't matter. Feel free to ask. The code in above post is an example of "swapping pointers".

1

I appriciate adatapost for this kind of encouragements.

While swaping try call by value and also try call by reference.

Votes + Comments
and you too.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.