Computer Science, asked by Muskangarg2186, 8 months ago

Develop a program to display the content of file supplied as command line arguments

Answers

Answered by theking20
0

A program to display the content of file supplied as command line arguments is as follows:

  • The command line argument passing is one of the features in Java. These are passed while running a particular Java program.
  • Here, the arguments are passed from the user interface, and these parameters are received in the program itself.

Example program:

class ProgramCommandLineArgument{  

public static void main(String abcd[]){  

System.out.println("Your first argument is: "+abcd[0]);  

}

Answered by mad210219
0

Given:

content of file

To find:

A program to display the content of file supplied as command line arguments

Solution:

#include <iostream>  

using namespace std;  

 

int main(int argc, char** argv)   ?? command line arguments

{  

   cout << "You have entered " <<endl;

s=fopen(argv[i],r);  //opening file

while(s !=0) //printing until empty

{

Count<<s<<;

}

Fclose(); //closing files  

   return 0;  

}  

argc (ARGument Count) is int and stores number of command-line arguments passed by the user including the name of the program. So if we pass a value to a program, value of argc would be 2 (one for argument and one for program name)

The value of argc should be non negative.

argv(ARGument Vector) is array of character pointers listing all the arguments.

If argc is greater than zero,the array elements from argv[0] to argv[argc-1] will contain pointers to strings.

Argv[0] is the name of the program , After that till argv[argc-1] every element is command -line arguments.

Similar questions