I have written a program to accept and print but getting errors in accepting 2d arrays.
error:-
thread 'main' panicked at 'called Result::unwrap()
on an Err
value: ParseIntError { kind: InvalidDigit }', test1.rs:15:39
note: run with RUST_BACKTRACE=1
environment variable to display a backtrace
use std::io;
fn main() {
let width = 3;
let height = 3;
let mut array = vec![vec![0; width]; height];
let mut input_text = String::new();
for i in 0..width {
for j in 0..height {
io::stdin()
.read_line(&mut input_text)
.expect("failed to read from stdin");
let trimmed = input_text.trim();
let t:u32=trimmed.parse().unwrap(); //error
array[i][j]=t;
println!("{:?}", array);
}
}
println!("{:?}", array);
}
OUTPUT :- 1
[[1, 0, 0], [0, 0, 0], [0, 0, 0]]
2
thread 'main' panicked at 'called Result::unwrap()
on an Err
value: ParseIntError { kind: InvalidDigit }', test1.rs:15:39
note: run with RUST_BACKTRACE=1
environment variable to display a backtrace