943,670 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1237
  • C RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jul 14th, 2009
0

Re: String Swap Not Working

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.
Reputation Points: 22
Solved Threads: 12
Junior Poster
Dream2code is offline Offline
144 posts
since Jun 2009
Jul 14th, 2009
0

Re: String Swap Not Working

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
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Printing Question
Next Thread in C Forum Timeline: Postfix operation





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC