コード例 #1
0
ファイル: e1-22.c プロジェクト: plonk/exercises
/* 行をある桁で折り返す */
int main()
{
  int COLS = 30;
  int c, col;

  char buf[1000];
  int i = 0;

  col = 0;

  while ((c = getchar()) != EOF) {
    if (c == '\t')
      col = next_tabstop(col);
    else
      ++col;

    buf[i++] = c;
    if (col == COLS) {
      print_to_last_nonblank(buf, i);
      putchar('\n');
      col = 0;
      i = 0;
    }
    if (c == '\n') {
      print_first(buf, i);
      col = 0;
      i = 0;
    }
  }
  return 0;
}
コード例 #2
0
ファイル: entab.c プロジェクト: zastari/Worked_Solutions
void entab_list(int *tabstops)
{
    int c, buf, col = 0;
    while((c = getchar()) != EOF) {
        if(c == ' ') {
            if(*(tabstops = next_tabstop(tabstops, col)) == -1) {
                /* No more tabstops; ignore entabbing */
                putchar(c);
                continue;
            }

            buf = 0;
            do {
                buf++, col++;
            } while(col < *tabstops && (c = getchar()) == ' ');

            if(col == *tabstops) {
                putchar('\t');
            }
            else if(c != '\t') {
                while(buf-- > 0) {
                    putchar(' ');
                }
            }
        }
        if(c != ' ') {
            putchar(c);
            col++;
            if(c == '\n') {
                col = 0;
            }
            else if(c == '\t') {
                if(*(tabstops = next_tabstop(tabstops, col)) != -1) {
                    col = *tabstops;
                }
            }
        }
    }
}