11-1

テストがムズかしくなってきた。

/*
 * 入力中の行、単語、文字のカウント
 **/
main(){
  int c, nl, nw, nc, state;

  state = OUT;
  nl = nw = nc = 0;
  
	while((c = getchar()) != EOF ){
		++nc;
		if( c == '\n') { ++nl; }
		if( c == ' ' || c == '\n' || c == '\t'){ state = OUT; }
		else if ( state == OUT ) { 
			state = IN;
			++nw;
		}
	}
	
	printf("%d %d %d\n",nl,nw,nc);

  exit(0);

}

rubyスクリプトを書いて、それを標準出力から流して作ったプログラムに
食わせる。

#!/usr/local/bin/ruby

statements = <<EOS
words 5 and
2 lines
EOS

#p statements.size -> 20
print statements
:!ruby 1-11.test.rb | ./1-11
[No write since last change]
2 15 20

Press ENTER or type command to continue

OK.