text: #include <stdio.h>
  
  #define MAXLINE 1000
  
  int getLine(char s[], int lim);
  
  int main()
  {
      int len;
      char line[MAXLINE];
  
      while ((len = getLine(line, MAXLINE)) > 0)
      {
          while (len > 0 && (line[len - 2] == ' ' || line[len - 2] == '\t'))
          {
              line[--len] = '\0';
          }
  
          // Do something with line...
          printf("%d\n", len);
      }
  
      return 0;
  }
  
  int getLine(char s[], int lim)
  {
      int c, i;
  
      for (i = 0; (c = getchar()) != EOF && c != '\n'; i++)
      {
          if (i < (lim - 1))
          {
              s[i] = c;
          }
      }
  
      if (c == '\n')
      {
          if (i < (lim - 1))
          {
              s[i] = c;
              s[++i] = '\0';
          }
          else
          {
              s[lim - 1] = c;
              s[lim] = '\0';
              i++;
          }
      }
      else if (i < (lim - 1))
      {
          s[i] = '\0';
      }
      else
      {
          s[lim - 1] = '\0';
      }
  
      return i;
  }
  