FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
389 views
in RTU/BTU B.Tech(CSE-I & II Sem) Computer Programming Lab by Goeduhub's Expert (7.6k points)
Programs to input data through Command line argument.

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.6k points)
edited by
 
Best answer

Command line arguments 

Command line arguments : Command line arguments are simply arguments that are specified after the name of the program in the system’s command line, and these argument values are passed on to your program during program execution.

Syntax : int main(int argc, char *argv[] )  

Here, argc counts the number of arguments. It counts the file name as the first argument.

The argv[] contains the total number of arguments. The first argument is the file name always.

Example 1 : Program file : x.c

#include<stdio.h>
#include<conio.h>
void main()
{
printf("GoEduHub Welcomes You");
}

Open command prompt and compile the file using "gcc file_name.c" then, after compilation of file it will create a ".exe" file  my file is "a.exe" . It will display content of your file .

Example 2 : program file : X.c

#include <stdlib.h> 

#include <stdio.h>      

int main(int argc, char** argv)

{

  printf("Program name is: %s\n", argv[0]);  

  printf("First argument is: %s\n", argv[1]);  

  printf("second argument is: %s\n", argv[2]);  

  printf("third argument is: %s\n", argv[3]);  

  return 0;  

}

Open command prompt and compile the file using "gcc file_name.c" then, after compilation of file it will create a ".exe" file  my file is "a.exe" .  now write "a arg1"

For more RTU/BTU II Sem Computer Programming Lab  Experiments CLICK HERE

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...