teach me buffer and it's interaction with function? : Guyz,
i am facing some problem while understanding the following code.
It is a program to read Strings from keyboard if the length of the String is lesser than the specified size(i.e 'n' here )
.

if length of the string is larger than the specified size it will discard the other next character.

**more Specifically i want to know what is happening inside buffer and how getchar() is reading the data and not storing in buffer.**  


    char * s_gets(char * st, int n)

    {

         char * ret_val;
         int i = 0;
         ret_val = fgets(st, n, stdin);

         if (ret_val) // i.e., ret_val != NULL
         {
              while (st[i] != '\n' && st[i] != '\0')
              i++;

              if (st[i] == '\n')
                   st[i] = '\0';

              else // must have words[i] == '\0'
              while (getchar() != '\n')
                    continue;

         }

     return ret_val;

    }