title: Input handling using while in c
body: <p>I want to make a program that handles the user input, more specifically the typed slashes ("/"). I used a variable to count them. The problem is, it says "error." every time I do a correct input, in this case 2 slashes (//).</p>
  
  <p>THIS WORKS</p>
  
  <p>Insert a string: //</p>
  
  <p>ok.</p>
  
  <p>THIS DOESN'T WORK</p>
  
  <p>Insert a string: ///</p>
  
  <p>error.</p>
  
  <p>Insert a string: //</p>
  
  <p>error.             - it should be "ok.". Why it says error?</p>
  
  <p>I used to debug my program and found that the application never quits the while loop, so it doesn't know the final slash count value. I'm asking for help.</p>
  
  <pre><code>char input[50];
  int slash_count = 0;
  int i;
  printf("Insert a string: ");
  scanf("%s", input);
  for(i=0; i&lt;strlen(input); i++)
  {
      if (input[i] == '/')
      {
          slash_count++;
      }
  }
  while (slash_count != 2)
  {
      printf("error.\n");
      printf("Insert a string: ");
      scanf("%s", input);
  }
  printf("ok");
  </code></pre>