change putc to use write