Added text input and file reading

This commit is contained in:
BayThylacine 2024-09-17 13:03:07 +00:00
parent 3d57d7df0d
commit ff57a5dc6b
5 changed files with 37 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

7
Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "TextAdventureEngine"
version = "0.1.0"

6
Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[package]
name = "TextAdventureEngine"
version = "0.1.0"
edition = "2021"
[dependencies]

20
src/main.rs Normal file
View File

@ -0,0 +1,20 @@
use std::io;
use std::io::BufRead;
use std::io::Read;
use std::io::Error;
use std::fs::File;
fn main() -> std::io::Result<()> {
println!("Please enter the path to the config file. ");
let mut s=String::new();
let stdin = io::stdin();
let mut handle = stdin.lock();
handle.read_line(&mut s).unwrap();
let s: String = s.trim().parse().unwrap();
println!("You typed: {}",s);
let mut read = File::open(s)?;
let mut contents = String::new();
read.read_to_string(&mut contents)?;
println!("{}",contents);
Ok(())
}

3
test.txt Normal file
View File

@ -0,0 +1,3 @@
hello
my name
is Ethan