title: Validating a user input "string" length (C language)
body: <p>I'm trying to make a small program that reads the input from a user, and only accept a String with a length of 1. Also, it must either be a 'm', 'o', 'r', 'i' or 'c'.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  
  #define CODE_METRO_BUS 'm'
  #define CODE_OMNIBUS 'o'
  #define CODE_RAPIDE 'r'
  #define CODE_INTEGRE 'i'
  #define CODE_CARTE_ORANGE 'c'
  
  char userInput[50];
  
  printf("Enter the desired service:\n");
  printf("\n");
  printf("(Enter M) Metro/Bus\n");
  printf("(Enter O) Train/Omnibus\n");
  printf("(Enter R) Train rapide\n");
  printf("(Enter I) Transport integre\n");
  printf("(Enter C) Carte orange\n");
  printf("\n");
  printf("Choice: ");
  
  fflush(stdin);
  scanf("%s",userInput);
  while ((userInput!= CODE_METRO_BUS &amp;&amp;
          userInput!= CODE_OMNIBUS &amp;&amp;
          userInput!= CODE_RAPIDE &amp;&amp;
          userInput!= CODE_INTEGRE &amp;&amp;
          userInput!= CODE_CARTE_ORANGE) ||
          (strlen(userInput&gt; 1)) ) {
  
      printf("Error! Retry: ");
      fflush(stdin);
      scanf("%s",userInput);
  }
  </code></pre>
  
  <p>I'm just really not sure how I could do it. When I tried by using char, it was half working because, let's say I entered on input "mfybsn", the program just detected the first letter (which is 'm') and it validated as correct. But obviously, "mfybsn" is not = to 'm' even though my old program thinks it was for some reasons.</p>
  
  <p>Now as I said, I'm trying to use strings to only accept "userInput" if it has a length of 1 (and other conditions), but I can't manage to achieve it. Thanks in advance.</p>