title: How does this code print only unique characters from arguments? (Code Logic)
body: <p>Checklist:</p>
  <ul>
  <li><p>This program takes two strings and displays, without doubles, the
  characters that appear in either one of the strings.</p>
  </li>
  <li><p>The display will be in the order characters appear in the command
  line, and will be followed by a \n.</p>
  </li>
  <li><p>If the number of arguments is not 2, the program displays \n.</p>
  </li>
  </ul>
  <p>Code:</p>
  <pre><code>#include &lt;unistd.h&gt;
      
      int main(int argc, char *argv[])
      {
          int used[255] = {0};
          int i = 1, j = 0;
          if(argc == 3)
          {
              while(i &lt; 3)
              {
                  j = 0;
                  while(argv[i][j])
                  {
                      if(!used[(unsigned char)argv[i][j]])
                      {
                      used[(unsigned char)argv[i][j]] = 1;
                          write(1, &amp;argv[i][j], 1);
                      }
                      j++;
                  }
                  i++;
              }
          }
          write(1, &quot;\n&quot;, 1);
          return (0);
      }
  </code></pre>
  <p>I understand argument passing part that
  argv[0] is the program name,argv[1] is the second string in the string array argv, and strings are character arrays so argv[1][0] is the first character in the second string, argv[1][1] is the second character in the second string and so on.</p>
  <p>but how does the below part works <code>how is it printing unique characters only once from both arguments?</code></p>
  <pre><code>                j = 0;    
                  while(argv[i][j])//while argv[i][j] != '\0'
                  {
                      if(!used[(unsigned char)argv[i][j]])
                      {
                      used[(unsigned char)argv[i][j]] = 1;
                          write(1, &amp;argv[i][j], 1);
                      }
                      j++;
                  }
  </code></pre>
  <p>I cannot get the logic. Somebody, who is a C expert, please help me to understand the logic. Thanks for your help.</p>