Hi its me Dharani again with a blog ...
Requirements : " Gcc compiler installed and Cmd(command prompt)"
****I will be using SublimeText3 for coding no worries you do those stuff with notepad itself*****
Note: Gcc is used to compile the program bcz cmd does not know any programming languages..
Cmd acts as console to compile and run the program ...
Cool..!
Lets get Started..
Hoping Gcc has been installed on your system.
First you need a Piece of code to start with..
//MyFirstProgram.----C program to print all arguments given through command line.
Source code:
#include<stdio.h>
void main(int argc, char const *argv[])
{
/* code */
int a,b,c;
printf("Enter the Three Values:");
scanf("%d %d %d",&a,&b,&c);
printf("Values in the arguments: \n a is %d b is %d c is %d", a,b,c);
}
Save this code in Notepad File and save as ..
somefilename.c
Now its time to compile and run
open the cmd...
now goto the Respository where you have saved the code..
Here i have my Respositiory like this
>>D:\D INSTALL\TDM-GCC-32\Programs
About : " how to use command line arugments in c"
Requirements : " Gcc compiler installed and Cmd(command prompt)"
****I will be using SublimeText3 for coding no worries you do those stuff with notepad itself*****
Note: Gcc is used to compile the program bcz cmd does not know any programming languages..
Cmd acts as console to compile and run the program ...
Cool..!
Lets get Started..
Hoping Gcc has been installed on your system.
First you need a Piece of code to start with..
//MyFirstProgram.----C program to print all arguments given through command line.
Source code:
#include<stdio.h>
void main(int argc, char const *argv[])
{
/* code */
int a,b,c;
printf("Enter the Three Values:");
scanf("%d %d %d",&a,&b,&c);
printf("Values in the arguments: \n a is %d b is %d c is %d", a,b,c);
}
Save this code in Notepad File and save as ..
somefilename.c
Now its time to compile and run
open the cmd...
now goto the Respository where you have saved the code..
Here i have my Respositiory like this
>>D:\D INSTALL\TDM-GCC-32\Programs
To run the Program..
>>type gcc filename.c -o anyname.exe
Here MyProgram name is AllArgu i have saved as AllArgu.c and my output file name is also the i have kept as allargu.exe
Once you have do this it will compile the program and create a allargu.exe file ...
Now you have to run the allargu.exe file
To run the command will be like this
>>allargu and send the arguments it will be reach the program
eg:
allargu
once you have typed the arguments and hit the enter button
it will provide you the output
Have a quires?? Feel free to Comment Below..
Thank you!
Come Back to Learn More From Tech Bird.
Comments