Free coupon for initial registration

Print passed parameters(ARGVs) through command line

Contents [hide]

Output

-a
-b
-c

Input

1
-a -b -c

Programming code example

C

1
2
3
4
5
6
7
#include <stdio.h>
int main(int argc , char *argv[]){
    int i;
    for(i = 1;i < argc;i++) {
        printf("%s\n", argv[i]);
    }
}

C++

1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;
int main(int argc, char* argv[]){
    for(int i=0; i<argc; i++) {
        std::cout << argv[i] << endl;
    }
    return 0;
}

C#

1
2
3
4
5
6
7
8
using System;
public class argv {
    public static void Main(string[] args)  {
        foreach (string argv in args) {
            Console.WriteLine(argv);
        }
    }
}

Go

1
2
3
4
5
6
7
8
9
10
11
package main
import (
    "fmt"
    "os"
)
 
func main() {
    for i := range os.Args {
        fmt.Printf("%s\n", os.Args[i])
    }
}

Java

1
2
3
4
5
6
7
class argv {
    public static void main(String argv[]){
        for ( int i = 0; i < argv.length; i++){
            System.out.println(argv[i]);
        }
    }
}

JavaScript

1
2
3
for (var i=2;i < process.argv.length;i++) {
    console.log(process.argv[i]);
}

PHP

1
2
3
4
<?php
for ($i=1; $i<count($argv); $i++) {
    print($argv[$i]."\n");
}

Perl

1
2
3
foreach my $argv (@ARGV) {
    print $argv."\n";
}

Python

1
2
3
import sys
for item in sys.argv[1:]:
    print(item)

Ruby

1
2
3
ARGV.each_with_index do |arg, i|
    puts "#{arg}"
end

Rust

1
2
3
4
5
6
use std::env;
fn main() {
    for arg in env::args() {
        println!("{}", arg);
    }
}

Shell

1
2
3
4
for var in "$@"
do
    echo "$var"
done

You can find programming examples to solve same problem using multiple programming languages.
Please find best programming language for your problems and solution.
Covering all cases: JavaScript Perl PHP Python Ruby | Covering some cases: C C++ C# Go Java Rust Shell
 
Big categories
Array | Class | Database | File systems | Network | Number | String | System | Test | Time | Variable
Other useful content
  1. Popular programming languages
  2. Popular web framework
  3. VPS Ranking.com (Find best VPS based on benchmark)
Free coupon for initial registration