Question: This is rust language. The goal of a program will be to print the nth character of a given file. This will give us with

This is rust language. The goal of a program will be to print the nth character of a given file.

This will give us with handling program arguments, working with strings and slices, working with files, and converting strings to integers.

Here is my code, but I do not get it.

use std::env;

use std::error::Error;

use std::fs::File;

use std::io::BufReader;

use std::io::prelude::*;

use std::path::Path;

use std::io::Read;

fn main() {

//Create a path to the desired file

let path = Path::new("input_file.txt");

let display = path.display();

//Open the path in read-only mode, returns 'io::Result'

let file = match File::open(&path) {

Err(why) => panic!("not open {}: {}", display, why.descripthion()), Ok(file) => file,

};

let reader = BufReader::new(file);

for line in reader.lines() {

match line {

Ok(file) => {

if valid(&line) {

println!("{}", line)

}

}

Err(e) => println!("Error: {}", e),

}

}

//let args: Vec = env::args().collect();

// The first argument is the path that was used to call the program.

//println!("My path is {}.", args[0]);

// The rest of the arguments are the passed command line parameters. $ ./args arg1 arg2

//println!("I got {:?} arguments: {:?}.", args.len() - 1, &args[1..]);

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!