ADVERTISEMENT
ADVERTISEMENT

Rust program to print the count of command-line argument using library function

Rust Example: Write a program to print the count of command-line argument using library function.
Submitted by Nidhi, on November 26, 2021

Problem Solution:

In this program, we will count the total number of the command-line argument passed using the len() function and print the result.

Note: The program name is the first argument of "Command Line Arguments".

Program/Source Code:

The source code to print the count of command-line arguments using the library function is given below. The given program is compiled and executed on UBUNTU 18.04 successfully.

// Rust program to print the count of 
// command line argument 
// using library function

fn main(){
   let args = std::env::args();    
   println!("Total command line arguments are: {}",args.len());
}

Output:

Compile:
$ rustc main.rs

Execute:
$ ./main One Two Three
Total command line arguments are: 4

Explanation:

In the main() function, we printed the count of command-line arguments using the len() function.

Rust Miscellaneous Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.