title: C Segmentation Fault (core dumped) error in code
body: <p>I'm trying to solve a problem :</p>
  
  <p>The task is -</p>
  
  <p>Given an array of strings sorted in lexicographical order, print all of its permutations in strict lexicographical order. If two permutations look the same, only print one of them. See the 'note' below for an example.</p>
  
  <p>Complete the function next_permutation which generates the permutations in the described order.</p>
  
  <p>For example, The six permutations in the correct order are:</p>
  
  <p>ab bc cd
  ab cd bc
  bc ab cd
  bc cd ab
  cd ab bc
  cd bc ab</p>
  
  <p>Note: There may be two or more of the same string as elements of s.</p>
  
  <p>For example,s = [ab,ab,bc] . Only one instance of a permutation where all elements match should be printed. In other words, ifs[0] == s<a href="https://onlinegdb.com/Sk4FC5FfU" rel="nofollow noreferrer">1</a> , then print either s[0] s<a href="https://onlinegdb.com/Sk4FC5FfU" rel="nofollow noreferrer">1</a> or s<a href="https://onlinegdb.com/Sk4FC5FfU" rel="nofollow noreferrer">1</a> s[0] but not both.</p>
  
  <p>A three element array having three discrete elements has six permutations as shown above. In this case, there are three matching pairs of permutations wheres[0] = ab and s<a href="https://onlinegdb.com/Sk4FC5FfU" rel="nofollow noreferrer">1</a> = ab are switched. We only print the three visibly unique permutations:</p>
  
  <p>ab ab bc
  ab bc ab
  bc ab ab</p>
  
  <p>Input Format</p>
  
  <p>The first line of each test file contains a single integer n, the length of the string array s.</p>
  
  <p>Each of the next n lines contains a string s[i].</p>
  
  <p>Sample Input 0</p>
  
  <p>2
  ab
  cd</p>
  
  <p>Sample Output 0</p>
  
  <p>ab cd
  cd ab</p>
  
  <p>And <a href="https://onlinegdb.com/Sk4FC5FfU" rel="nofollow noreferrer">this</a> is the code I wrote.</p>
  
  <p>But I'm getting segmentation fault (core dumped) error</p>
  
  <p>As per my knowledge segmentation fault is encountered when we access something which no longer exists.  But I don't think I'm doing so.</p>
  
  <p>Thanks!</p>