kandr/ch1/trim_whitespace.c
int trimmed_getline(char s[], int lim) {
  int c, i, l;

  for (i=0, l=0;(c=getchar()) != EOF && c != '\n'; i++) {
    if (i < lim-1) {
      s[i] = c;
      if (c != ' ' && c != '\t') {
        l = i;
      }
    }
  }
  if (i > l+1) {
    i = l;
  }
  if (c == '\n') {
    s[i] = c;
    i++;
  }
  s[i] = '\0';
  return i;
}
/* get trimmed line with trailing whitespace removed */
get trimmed line with trailing whitespace removed
get trimmed line with trailing whitespace removed
int trimmed_getline(char s[], int lim) {
  int c, i, l;
  for (i=0, l=0;(c=getchar()) != EOF && c != '\n'; i++) {
    if (i < lim-1) {
      s[i] = c;
      if (c != ' ' && c != '\t') {
        l = i;
      }
    }
  }
  if (i > l+1) {
    i = l;
  }
  if (c == '\n') {
    s[i] = c;
    i++;
  }
  s[i] = '\0';
  return i;
}
int trimmed_getline ( char s [ ] , int lim ) { int c , i , l ; for ( i = 0 , l = 0 ; ( c = getchar ( ) ) != EOF && c != ' \n ' ; i ++ ) { if ( i < lim - 1 ) { s [ i ] = c ; if ( c != ' ' && c != ' \t ' ) { l = i ; } } } if ( i > l + 1 ) { i = l ; } if ( c == ' \n ' ) { s [ i ] = c ; i ++ ; } s [ i ] = ' \0 ' ; return i ; }
get trimmed line with trailing whitespace removed
get trimmed line with trailing whitespace removed