title: String swap by swap function
body: <p>I have written code to swap strings, but I am not able to swap. What is the problem and how can I solve it by using a function, <code>swap</code>?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void swap( char*,char*);
  int main()
  {
      char *ptr[2] = {"hello", "morning"};
      swap(ptr[0], ptr[1]);
      printf("%s %s", ptr[0], ptr[1]);
      return 0;
  }
  
  void swap(char *t1, char*t2)
  {
      char *t;
      t = t1;
  
      t1 = t2;
      t2 = t;
  }
  </code></pre>
  
  <p>I also tried to pass <code>(&amp;ptr[0], &amp;ptr[1])</code>, but here it shows a <a href="http://en.wikipedia.org/wiki/Segmentation_fault" rel="nofollow"><code>segmentation fault</code></a>. Also I made a char, <code>*p1 = ptr[0], char *p1 =  ptr[1]</code>, and then passes <code>&amp;p1</code>, and <code>&amp;p2</code> to <code>swap</code>, but still I get a segmentation fault.</p>