title: Flush stdin using fgets
body: <p>Trying to make a registration page through the console.
  I need several inputs for it, and I'm using fgets, so I need to flush stdin.
  Lots of similar questions on Stack Overflow redirected here: <a href="http://c-faq.com/stdio/stdinflush2.html" rel="nofollow">http://c-faq.com/stdio/stdinflush2.html</a>.
  I got the code below using that link. However, this doesn't actually work. It says Username:, and then when I type in a username, and press enter, it just goes to a new, empty line in console where I can type in more.
  Why is this happening?
  How can I fix it?</p>
  
  <p>EDIT: Added code</p>
  
  <pre><code>NSLog(@"Do you have an account already?(1 for Yes, 0 for no)");
      fgets(cnumb1, 2, stdin);
      int c;
      while((c = getchar()) != '\n' &amp;&amp; c != EOF);
      size_t length = strlen(cnumb1);
      if (cnumb1 [length-1] == '\n'){ // In case that the input string has 1 character plus '\n'
          cnumb1 [length-1] = '\0';} // Plus '\0', the '\n' isn't added and the if condition is false.
      NSString* string = [NSString stringWithUTF8String: cnumb1];
      if (string == 0) {
          while(numb4 == 1) {
              numb3 = 1;
              while( numb3 == 1){
                  NSLog(@"Username:");
                  fgets(usercheck1, 13, stdin);
                  int c2;
                  while((c2 = getchar()) != '\n' &amp;&amp; c2 != EOF);
                  size_t length1 = strlen(usercheck1);
                  if (usercheck1 [length1-1] == '\n'){ // In case that the input string has 12 characters plus '\n'
                      usercheck1 [length1-1] = '\0';} // Plus '\0', the '\n' isn't added and the if condition is false.
  </code></pre>