String Swap Not Working

Reply

Join Date: Jun 2009
Posts: 139
Reputation: Dream2code is an unknown quantity at this point 
Solved Threads: 11
Dream2code's Avatar
Dream2code Dream2code is offline Offline
Junior Poster

Re: String Swap Not Working

 
0
  #11
Jul 14th, 2009
just like to add a point here,When we use
strcpy() function it actuaylly copies the 2nd string to the 1st one.

but when we assign
*p=x;
x=*q
*q=*p
like this here we only interchange the address variable.

these two things gives the same output but internal operation is different.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 169
Reputation: tuse is an unknown quantity at this point 
Solved Threads: 14
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: String Swap Not Working

 
0
  #12
Jul 14th, 2009
Originally Posted by Kurt Kubing View Post
I think there's only one reason why your code will never work as you expected: you declare read-only strings. Although you didn't declare it with the const keyword, declaring string that way makes your string variable untouchable.
Its possible that what the original thread starter meant by 'swap' was to actually interchange the pointers to the read-only strings as Dave and Dream2Code have suggested.
Last edited by tuse; Jul 14th, 2009 at 3:38 am. Reason: typo
My blog on .NET- http://dotnet.tekyt.info
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC