Skip to content

Instantly share code, notes, and snippets.

@fredemmott
Created June 29, 2020 18:25
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 fredemmott/3f783569d0fa317514b9aae0500b20f0 to your computer and use it in GitHub Desktop.
Save fredemmott/3f783569d0fa317514b9aae0500b20f0 to your computer and use it in GitHub Desktop.
fredemmott@fredemmott-fbmbp foo % echo -en "" | ./target/debug/foo
fredemmott@fredemmott-fbmbp foo % echo -en "\n" | ./target/debug/foo
Line: ''
fredemmott@fredemmott-fbmbp foo % echo -en "foo" | ./target/debug/foo
Line: 'foo'
fredemmott@fredemmott-fbmbp foo % echo -en "foo\n" | ./target/debug/foo
Line: 'foo'
fredemmott@fredemmott-fbmbp foo % echo -en "" | ./a.out
fredemmott@fredemmott-fbmbp foo % echo -en "\n" | ./a.out
Line: ''
fredemmott@fredemmott-fbmbp foo % echo -en "foo" | ./a.out
Line: 'foo'
fredemmott@fredemmott-fbmbp foo % echo -en "foo\n" | ./a.out
Line: 'foo'
use std::io::prelude::*;
use std::io::BufReader;
use std::fs::File;
fn main() -> std::io::Result<()> {
let mut reader = BufReader::new(std::io::stdin());
for line in reader.lines() {
println!("Line: '{}'", &line?);
}
Ok(())
}
#include <stdio.h>
int main() {
char buf[1024];
while (gets(buf)) {
printf("Line: '%s'\n", buf);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment