zoom1 zoom2 zoom3
Menu

philippewang.info

line2dots

Reads from stdin and puts to stdout a dot (.) each time it reads a newline.
#include <stdio.h>
#include <stdlib.h>

void putdot(){
  putchar('.');
  fflush(stdout);
}

int main (int argc, char** argv) {
  while(1) {
    switch (getchar()) {
    case '\n':
      putdot();
      switch (getchar()) {
      case '\n':
        putdot();
        break;
      default:
        break;
      }
      break;
    case '\r':
      putdot();
      switch (getchar()) {
      case '\r':
        putdot();
        break;
      default:
        break;
      }
      break;
    case EOF:
      putchar('\n');
      return 0;
    default:
      break;
    }
  }
}

/* end of line2dots.c                                              */
It is equivalent to
#!/bin/sh
while read ; do echo -n '.' ; done ; echo

:: philippewang.info ::

:: design & photos :: XHTML 1.1 :: CSS 2 :: RSS 2 :: stats :: contact ::
:: Best viewed with Safari or Opera or Firefox or Links :: No SPAM Please ::
 
This page was generated on Sun Jul 29 16:10:02 CEST 2007 by BashGXD