Skip to content

Instantly share code, notes, and snippets.

@wperron
Created October 31, 2022 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wperron/066621c73725e905f1c8cbb2f45879af to your computer and use it in GitHub Desktop.
Save wperron/066621c73725e905f1c8cbb2f45879af to your computer and use it in GitHub Desktop.
print the printable portion of ascii character space
use std::io::{self, Write};
fn main() {
write_ascii(std::io::stdout()).unwrap();
}
fn write_ascii<W: Write>(mut w: W) -> Result<(), io::Error> {
let chars = (0x20 as u8..0x7e + 1 as u8)
.into_iter()
.map(|b| char::from(b))
.collect::<Vec<char>>();
for c in chars.chunks(16) {
write!(w, "{}\n", c.iter().collect::<String>())?
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment