60 - COMMAND LINE ARGUMENTS - C PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel so previous sessions we are dealing with the data structures and these days I am getting more requests on the command line arguments so most of the viewers are sending the request regarding this command line arguments in C so in today's session we'll go with the command line arguments and then from the next session we will continue the data structures right so command line arguments in C right so the name itself indicates command line arguments so where we have seen these Ultimates so whenever we studied the functions concept in the fractious concept we have covered these arguments so whatever the inputs given to the function that those inputs we'll call them as arguments so here we are giving the arguments in a command line right so that means without using the input function without using the input function so what's the input function here so scanf right so without using this scanner we can pass the inputs through command line so we can pass the inputs to command line right so we need not use this sense kind of functions till we can execute the programs so for this so whatever the arguments we are passing in command line all those arguments should be passed in main function this argument should be returning main function right so so this way these arguments are two arguments we have to write in the main function two arguments so one is for argument count so he will count the number of arguments where possible okay and the second one is it is argument value and it is an array which is of character data and it is an integer greater it's a character data so whatever the other words we are passing those ornaments house will be here and the actual value will be in this and okay and this hat is a character so what are the arguments we are passing through the command line those will be in a character data type so if you want to perform the integer as we have to type convert this value right see now the C takes for this one is so these arguments should be positive main function so we have to write may in all C Hector are V right here main heat add C so two arguments what is the argument count second argument is argument value star or V [Music] sorry so why were giving the star moves here we are not we don't know how many arguments we're passing so we'll just you pass the address file so in the arc see character are weak so then we can write the program yeah okay see I will write the program let us write the program so may eat or count character star our value right simply we can break those values okay see pretty f % r HD r c and simply we can print this or we also see here so what are the always were passing in the current line the first one that makes 0th index 0 to index may be the finding the 0th index will be the file name and the first index will be the first value second index will be the second value and so on so always the r cubed value of 0 is a fine name so remember this one so argument V of 0 is a fine name so whatever a fine language whatever the fire we are implementing for this command line that file and will be here it will be printed here so I will show you the way executing this program so that if you are having any doubts should be clarified so you'll execute a program next a printf percentage yes our melee of zero so after writing the program see if you store this program if you save this program as CMD dot c CM d dot C so here the question is how to execute these type of programs so we should not here we are not giving any scatter so here the compiler will not prompt for the input so after saving the file the first step knees come by compile the program and you need not run the program here because here we are not giving a name right so we need not run the program here so go to the file menu 5 minutes in the 5 in 5 min oh you can observe the oh yes shell OS shell so if you click on this well shell the command prompt will be open command prompt will be open okay in the command prompt type the command Romanies filename space argument 1 space are you meant to space and so on so we'll have to view like this file name ultimate one i went to like this so this is the syntax for doing the program so this should be happy intimate room this should be happening Cameron Crowe right so if you execute this one if you exhibit this one in the command prompt in this command from just to time to see him be one space 2 space 3 so automatically we will get the output as so first argument count so argument crown means how many arguments are there 1 2 3 and including the file name so they also includes the file name so total four arguments so for an artery of zero are we are 0 means this one so the complete path will be displayed here the complete path will be displayed here okay in such a vein we can execute any command-line arguments so we can implement the addition of two numbers you can implement the factorial program we can implement the fibonacci program any program we can implement but without using the scanf and we have to pass the whole domain see main function so whatever the commands you are using here in the comment from those values will be directly copied into this up do it so first one I will count the number of arguments is calculated and that will be assigned to RC and this one by one it is an assigned to our movie okay so let us execute the program in the compiler so that your doubts will be clarified so I will execute two programs so we will see this program and we again we all will also execute the another program right so see once again the second argument that means all the argument values are enough character data type right so if you want to use an integer you have to take convert this data type okay so first the character should be a type casted to integer and then we'll have to perform it right so hope you understood this one so let us move on to the implementation part hello friends so now we will see the implementation part of this complete compiled command-line arguments so let us execute the program so first let us type the program same program which we have seen just now so here the main function will take the two arguments so in the arc C that means a argument count and a character star or value so these value these names need not be the same so you can take a and B also right but the first argument is there for argument count and the second argument is for argument value that's it so here we can write argument count is equal to percentage team odd see it just prints the how many arguments we are passing through the command-line arguments right next argument value is equal to percentage yes so as I said that the first index is nothing but the file name okay are we of 0 so just I will save this file CMD v dot C yes all right now just compile the program right and then execute the program now see once again I am saying how to writing the program save that file and then compile and then execute okay I just skipped that one okay execute the program then go to the OHL then go to the Ovation write the command CMD file space followed by arguments so you can observe here argument count is equal to 5 because see four values and the file name total 5 arguments are there so argument count is equal to 5 and arguing value of 0 the soul it is a first thing right the file name it will print the file name so it will print the complete path of the file name so eg turbo C 2 comment Exe so if you want to go back to the compiler just type the exit you will go back to the compiler now let us see this one so ultimate count you can write the for loop here int sorry I is equal to 1 I less than or see I plus place print error argument percentage D is for percentage yes I value and argument B of I will explain it so I am just at a printing all arguments okay I am printing all the arguments so printf filename percentage yes comma V of 0 see here you can observe right so save the file with the same file name then just printing all the arguments which are taken from the command line on the print on the screen right so here I am taking considering the value the loop variable I value with 1 because the 0 is the file name okay just to clear this one so the first step is compile second step is execute third step is go to OHL here you can write a CMD five one two three four five six seven eight nine ten so you can observe argument count is equal to ten numbers in the final total 11 file name is CMD v dot exe and are from the argument 1 you can observe 1 2 3 4 5 6 7 8 9 10 okay all these are the characters all these are the characters right see again we'll go with the another one so if you want to add all these things add the numbers so simply we have to do some plus is equal to okay I sum plus is equal to I means here I is in L so sorry our GUI of I so it doesn't work because our V of I is in a character data type so here we have to convert it into integer there is a direct function called a to I which converts the character into an integer right this convert the character into integer and it will calculate all the values of C so compile first one sorry not declared this one okay so compile this one zero errors run this one then third step go to the ovation here we can type CMD file space 1 2 3 4 5 6 so that means it will calculate the sum of 6 numbers so the result must be 11 plus 4 15 15 plus the ad 20 and 21 ok so we have not printed this one ok we just calculated the sum but we didn't write any printer so it doesn't print sum is equal to percentage team right now you can see compiled declaration syntax error what happened to this okay right eunuch confusion I'm riding and right so first step compiled second step run and then go to the over a shell and then here we have to print CMD five one two three four five so the output will be nine plus three 12 12 plus two 14 plus one so you can observe here the first one argument count that is six second one file name.for and so and the third one is sum is equal to 15 okay so hope you understood this one so like this we have to pass an arguments through the command line and from the command line all the arguments will be taken in a character format so according to our logic we need to type convert that character data type to our required data type and then we can apply the calculations right so hope you understood this one the very simple thing so rather than using the scan of we can pass the arguments in it command line that will be passed to the arguments for main function once the argument called another one is the argument value right so always the argument value the first the first index that means a 0th index of argument value will be the file name there's a these are the points to be remembered while implementing this command-line argument and the part of the procedure so after writing the program save the file with the dot c file then compile the program then compile the program then run the program and then go to the OHL and type the command the file name space the argument one space argument to space argument three and so on right so let us stop here if you really understood my sessions like my sessions and share my sessions and if you are having any doubts regarding this comment and arguments feel free to post your doubts in the comment section so that I will definitely try to clarify all your doubts and don't forget to subscribe to our channel thanks for watching
Info
Channel: Sundeep Saradhi Kanthety
Views: 29,547
Rating: 4.9273744 out of 5
Keywords: LANGUAGE, COMPUTER, c programming, c language, compiler, c compiler, binary, object code, c code, coding, exe code, .c, .obj, .exe, c files, sundeep, saradhi, kanthety, cp, computer basics, programming, software, c programming language, c language for beginners, cmd, command line, arguments, expale program, argument count, argument value, arrays
Id: Ww1yFSz8SDg
Channel Id: undefined
Length: 19min 40sec (1180 seconds)
Published: Thu Jul 04 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.