title: C - Comparing two characters
body: <p>I am having trouble comparing two characters. I've written a very basic C problem to try out command line arguments.</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  
  int main(int argc, char *argv[]) {
      char ch;
      char *type = "";
      char *gender = "";
      int baby = 0;
      int count = 0;
  
      /* Options:
       * -t = type of pet
       * -g = gender
       * -b = baby or adult
       */
      while ((ch = getopt(argc, argv, "t:g:b")) != EOF)
          switch (ch) {
              case 't':
                  type = optarg;
                  break;
              case 'g':
                  gender = optarg;
                  break;
              case 'b':
                  baby = 1;
                  break;
              default:
                  fprintf(stderr, "Invalid option.\n");
                  return 1;
          }
  
      argc -= optind;
      argv += optind;
  
      printf("You have chosen a %s.\n", type);
      if (gender == 'f')
          puts("It's a girl");
      if (gender == 'b')
          puts("It's a boy.");
  
      // The main command line arguments should be about the traits of the pet
      printf("%s", "Traits: ");
      for (count = 0; count &lt; argc; count++)
          printf("%s ", argv[count]);
  
      return 0;
  }
  </code></pre>
  
  <p>So if I type this into the terminal:</p>
  
  <pre><code>  $ ./pet_shop -t dog -g f cute small
  </code></pre>
  
  <p>I get this as output:</p>
  
  <pre><code>  You have chosen a dog:
    Traits: cute small
  </code></pre>
  
  <p>The output it missing information about the gender, it should be a girl since I entered f. But I tried checking by printf("%i", gender) which gave the value 0. Is g == 'f' the incorrect way of comparing two characters?</p>