954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Maybe too late but as the saying goes...

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.

Kurt Kubing
Newbie Poster
8 posts since Jul 2009
Reputation Points: 10
Solved Threads: 1
 

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".

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

I appriciate adatapost for this kind of encouragements.

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

Dream2code
Junior Poster
144 posts since Jun 2009
Reputation Points: 22
Solved Threads: 12
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You