<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: C++ SWAP function - help in Operating System - OpenVMS</title>
    <link>https://community.hpe.com/t5/operating-system-openvms/c-swap-function-help/m-p/3320638#M31226</link>
    <description>What is the exat problem you are having?&lt;BR /&gt;What do you want the swap to do when there is an odd number of characters?&lt;BR /&gt;&lt;BR /&gt;Here is something to get you going.&lt;BR /&gt;Works for me (with TWO spaces betweeb HELLOW and WORLD"&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO&gt;&lt;BR /&gt;&lt;BR /&gt;swap (char *string_pointer)&lt;BR /&gt;{&lt;BR /&gt;short temp, *short_pointer;&lt;BR /&gt;char c, *p;&lt;BR /&gt;&lt;BR /&gt;p = string_pointer;&lt;BR /&gt;short_pointer = (void *) p;&lt;BR /&gt;while (*p) {&lt;BR /&gt;  c = *p++;&lt;BR /&gt;  if (*p) {&lt;BR /&gt;    temp = (c &amp;lt;&amp;lt; 8) + *p++;&lt;BR /&gt;    *short_pointer++ = temp;&lt;BR /&gt;    }&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;main() {&lt;BR /&gt;char test[]="HELLOW  WORLD";&lt;BR /&gt;swap(test);&lt;BR /&gt;printf ("%s\n", test);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;$ cc tmp&lt;BR /&gt;$ lin tmp&lt;BR /&gt;$ run tmp&lt;BR /&gt;EHLLWO  OWLRD&lt;BR /&gt;$&lt;BR /&gt;&lt;BR /&gt;&lt;/STDIO&gt;</description>
    <pubDate>Thu, 01 Jul 2004 10:07:45 GMT</pubDate>
    <dc:creator>Hein van den Heuvel</dc:creator>
    <dc:date>2004-07-01T10:07:45Z</dc:date>
    <item>
      <title>C++ SWAP function - help</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/c-swap-function-help/m-p/3320637#M31225</link>
      <description>Hi every one&lt;BR /&gt;I have a problem writting a function which should &lt;BR /&gt;be able to output characters which are swapped i.e give then the input 'HELLOW WORLD'&lt;BR /&gt;the output should be 'EHLLWO OWLRD' can some one help.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Bonnie.</description>
      <pubDate>Thu, 01 Jul 2004 09:41:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/c-swap-function-help/m-p/3320637#M31225</guid>
      <dc:creator>Boniface Chiwenda</dc:creator>
      <dc:date>2004-07-01T09:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: C++ SWAP function - help</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/c-swap-function-help/m-p/3320638#M31226</link>
      <description>What is the exat problem you are having?&lt;BR /&gt;What do you want the swap to do when there is an odd number of characters?&lt;BR /&gt;&lt;BR /&gt;Here is something to get you going.&lt;BR /&gt;Works for me (with TWO spaces betweeb HELLOW and WORLD"&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO&gt;&lt;BR /&gt;&lt;BR /&gt;swap (char *string_pointer)&lt;BR /&gt;{&lt;BR /&gt;short temp, *short_pointer;&lt;BR /&gt;char c, *p;&lt;BR /&gt;&lt;BR /&gt;p = string_pointer;&lt;BR /&gt;short_pointer = (void *) p;&lt;BR /&gt;while (*p) {&lt;BR /&gt;  c = *p++;&lt;BR /&gt;  if (*p) {&lt;BR /&gt;    temp = (c &amp;lt;&amp;lt; 8) + *p++;&lt;BR /&gt;    *short_pointer++ = temp;&lt;BR /&gt;    }&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;main() {&lt;BR /&gt;char test[]="HELLOW  WORLD";&lt;BR /&gt;swap(test);&lt;BR /&gt;printf ("%s\n", test);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;$ cc tmp&lt;BR /&gt;$ lin tmp&lt;BR /&gt;$ run tmp&lt;BR /&gt;EHLLWO  OWLRD&lt;BR /&gt;$&lt;BR /&gt;&lt;BR /&gt;&lt;/STDIO&gt;</description>
      <pubDate>Thu, 01 Jul 2004 10:07:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/c-swap-function-help/m-p/3320638#M31226</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-07-01T10:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: C++ SWAP function - help</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/c-swap-function-help/m-p/3320639#M31227</link>
      <description>Great thanks for your help. If the sentence is &lt;BR /&gt;of odd number the last character is not switched with anything, but simply attached.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Bonnie.</description>
      <pubDate>Thu, 01 Jul 2004 10:22:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/c-swap-function-help/m-p/3320639#M31227</guid>
      <dc:creator>Boniface Chiwenda</dc:creator>
      <dc:date>2004-07-01T10:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: C++ SWAP function - help</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/c-swap-function-help/m-p/3320640#M31228</link>
      <description>Hi Hein,&lt;BR /&gt;sorry for disagree another time inthe same week :-o (never happened before!)&lt;BR /&gt; &lt;BR /&gt;Your code is quick but assume short as 16 bit that's is true in current C/C++ but may be false in future (or on other systems).&lt;BR /&gt;Also you assume char as 8 bit so your code can't work with wchar (known as unicode).&lt;BR /&gt;&lt;BR /&gt;This code is slower but more secure and more flexible:&lt;BR /&gt;&lt;BR /&gt;swap (char *string_pointer)&lt;BR /&gt;{&lt;BR /&gt;char c, *p, *p1;&lt;BR /&gt;&lt;BR /&gt;p = string_pointer;&lt;BR /&gt;while (*p)&lt;BR /&gt;{&lt;BR /&gt;  p1 = p;&lt;BR /&gt;  c = *p++;&lt;BR /&gt;  if (*p)&lt;BR /&gt;  {&lt;BR /&gt;    *p1 = *p;&lt;BR /&gt;    *p = c;&lt;BR /&gt;  }&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt; &lt;BR /&gt;Changing in above code 'char' with 'wchar' function can work using unicode.&lt;BR /&gt; &lt;BR /&gt;Regards&lt;BR /&gt;Antonio Vigliotti&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Jul 2004 10:42:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/c-swap-function-help/m-p/3320640#M31228</guid>
      <dc:creator>Antoniov.</dc:creator>
      <dc:date>2004-07-01T10:42:29Z</dc:date>
    </item>
  </channel>
</rss>

