Тёмный

Command Line Arguments | C Programming Tutorial 

Portfolio Courses
Подписаться 203 тыс.
Просмотров 56 тыс.
50% 1

An introduction to using command line arguments in C. Source code: github.com/portfoliocourses/c.... Check out www.portfoliocourses.com to build a portfolio that will impress employers!

Хобби

Опубликовано:

 

14 июл 2021

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 45   
@Anas-qh3hk
@Anas-qh3hk Год назад
Your channel is too underrated. Your way of explaining things is unbelievable, u make everything seems so easy to understand. It would be great if u made a video on how to explain things as you do in your videos
@PortfolioCourses
@PortfolioCourses Год назад
Wow thank you very much for the very kind feedback, I appreciate that, it's very encouraging to me. :-) Maybe one day I can make a video on "teaching CS" or something like that, that could be fun.
@iCrazy414
@iCrazy414 2 года назад
Simple case best cases to learn from. Too many tutorials make it way too fancy and confusing. Thank you for this video
@PortfolioCourses
@PortfolioCourses 2 года назад
You're welcome! :-D
@ramakrishna4092
@ramakrishna4092 2 года назад
@@PortfolioCourses hi sir I have been following your channel from month I came out one question where the command line arguments will get stored in memory . I searched in Google , stack overflow but I couldn't find anything.can you pls tell me where are the command line arguments will get stored if it's heap or stack someone answers I found in heap Can you pls clarify my doubt..
@PortfolioCourses
@PortfolioCourses 2 года назад
@@ramakrishna4092 Great question Rama! 🙂 It is not defined as part of the C language standard where the command-line arguments are stored. This means that it's technically possible for the command-line arguments to be stored on the stack OR the heap. As a practical matter though, I am unaware of any compiler that stores them on the heap, to my knowledge all compiler store them on the stack (as with other function arguments/parameters).
@lradhakrishnarao902
@lradhakrishnarao902 Год назад
@@PortfolioCourses Yes, agreed with you. Command line arguments are stored in an array, and because, they are associated with the main, which is a function, and are local arguments to the main function, there fore, it should be stored in a stack. Besides, Command line arguments are initialized inside main function, therefore, their scope is local to the main function. And variables, which have local scope, are stored inside stack.
@PortfolioCourses
@PortfolioCourses Год назад
@@lradhakrishnarao902 So if we have: int main(int argc, char *argv[]) then the variables argc and argv will definitely be local to main. We could also write **argv instead. But argv is really just "an array of pointers to strings" (however we want to phrase it). So while argv is a parameter in main, it stores a memory address where the actual data is, and the location in memory that it points to could technically be on the stack or the heap, we don't know.
@___nia
@___nia 8 месяцев назад
i started comp science major one month ago with no background in programming and your videos have been really helpful especially this one! thank you
@me_dimko
@me_dimko Год назад
Your channel is my go-to when I need any information about C language! Thank you for your work, I really appreciate you.
@PortfolioCourses
@PortfolioCourses Год назад
You're very welcome, I'm glad you find the channel useful, and thank you for the support! :-)
@dhunpatel5319
@dhunpatel5319 Год назад
I was doing my assignment. And i saw your video which is exactly what i want. Thank you so much🙂.
@PortfolioCourses
@PortfolioCourses Год назад
You're welcome, and good luck on your assignment Dhun! :-)
@stephanek9008
@stephanek9008 Год назад
You are a very good teacher. I hope you have videos on python and other languages. I have learned a lot from your videos. More info than an hour long tutorial
@PortfolioCourses
@PortfolioCourses Год назад
Thank you for the positive feedback Stephanek! :-) Right now in addition to C, I have playlists covering Python: Tutorials: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HhtcF4jEKNQ.html Examples: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ZLCZkMk69y0.html And I have playlists covering C++: Tutorials: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-qWPlRubVQ38.html Examples: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Fk-9KCBOsp8.html
@pietraderdetective8953
@pietraderdetective8953 8 месяцев назад
@@PortfolioCourses any chance you're going to make some Rust videos? looks like it's all the hype these days and there's not many channels covering it.
@boonie6
@boonie6 2 месяца назад
thank you so much, you somehow explained this in the best possible way.
@PortfolioCourses
@PortfolioCourses 2 месяца назад
You're welcome, I'm glad you enjoyed the explanation! :-)
@kuchkuch9304
@kuchkuch9304 Год назад
Very easy understanding and useful tutorial.
@PortfolioCourses
@PortfolioCourses Год назад
Thank you! 🙂 I'm really happy to hear that you found it easy to understand and useful!
@Fatih66622
@Fatih66622 Год назад
You are a great tutor. Keep going please.
@PortfolioCourses
@PortfolioCourses Год назад
Thank you very much for the kind feedback, I definitely intend to keep making more videos! :-)
@cipher1167
@cipher1167 6 месяцев назад
Very helpful!
@PortfolioCourses
@PortfolioCourses 6 месяцев назад
I’m glad it was helpful for you! :-)
@yoruichi5802
@yoruichi5802 Год назад
Your channel is the reference
@PortfolioCourses
@PortfolioCourses Год назад
Thank you! :-)
@DataStructures
@DataStructures Год назад
i am looking for some help. I want to do exactly what you did here. But instead of doing atoi to store the argument in an int, I want to store it inside of a char array. Let's say the input in the command line is a word. I want to put it in a char array. How do I do this?
@PortfolioCourses
@PortfolioCourses Год назад
Great question! I would try using strcpy() to copy the word into a char array, this video may help you out: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-RQ8O13utXQw.html. 🙂
@DataStructures
@DataStructures Год назад
@@PortfolioCourses it worked. Thanks so much for the helo
@phantom7333
@phantom7333 Год назад
Hello. I'm on windows and I have no idea how to work like you do through the command prompt (locate and run the program, etc). Could you help me with that?
@phantom7333
@phantom7333 Год назад
Maybe refer to a video of yours I haven't seen. Also, I'm new to this channel and you've been really helpful so far!
@ValliNayagamChokkalingam
@ValliNayagamChokkalingam Год назад
Is char *argv[] the same as char *argv ? Is it a charcater pointer - if yes, then should just passing char *argv or char argv[] work?
@PortfolioCourses
@PortfolioCourses Год назад
char *argv[] is an array of pointers to chars, and char *argv is a pointer to a char. So those are not equivalent. That said you'll often see char **argv used for the 2nd parameter instead of char *argv[], and that's actually fine because we don't actually have array parameters in C. When we have a parameter char array[] for a function really that just means char *array in practice, because when we "pass" arrays to functions what we really pass are pointers to the array (i.e. a pointer to the first element in the array). Personally I prefer char *argv[] because it communicates that we have an array of pointers to chars (i.e. strings), but I don't feel strongly about it either. :-)
@IO-_-Ol
@IO-_-Ol 5 месяцев назад
*argv[] is equivalent to **argv not *argv.
@germankoga8640
@germankoga8640 Год назад
What I don't understand is why would I use this instead of scanf, because in both cases I'm receiving an input from the user via terminal, just that in the first case is before executing the program, which also I find as a maybe issue because there's no feedback that arguments are expected or required since it can't be a printf before executing the program
@PortfolioCourses
@PortfolioCourses Год назад
Great question! :-) So one example of where you might do this is if you were creating a command-line utility of some sort. For example we use a tool like ssh to connect to remote servers: phoenixnap.com/kb/ssh-to-connect-to-remote-server-linux-or-windows. The tool accepts the server to connect to as a command-line argument, among other things. The people that use this tool are expected to know how it works, and there is what's called a "man page'" that allows them to learn how to use the command (in addition to other forms of documentation). Because it's a tool people use all the time as part of their work, they are expected to know how it works, as opposed to being provided with "an interface" that asks them questions (which would be much slower). We would say that this type of user is a "power user". Another advantage to command-line arguments is that we can then use our program as part of shell scripts. Shell scripts allow us to run programs and give them arguments via the command-line, so we can automate tasks and essentially "write a program that calls and uses other command-line programs": en.wikipedia.org/wiki/Shell_script.
@germankoga8640
@germankoga8640 Год назад
@@PortfolioCourses oh I see so it's like gcc where I'm expected to know how it works or read it elsewhere, and yes now that you say it, it does make it way faster and comfortable to use command line arguments instead of executing a program that ask a lot of questions, I more or less get the idea, thank you very much for the answer!
@PortfolioCourses
@PortfolioCourses Год назад
@@germankoga8640 You're welcome! 🙂
@zoquevil4792
@zoquevil4792 2 года назад
Thank you so much, your video is really Great!!! So helpful with all these details !!!! ------------------- At the end of the video I was asking myself: When was it specified in this code that there will be only 3 arguments? (hummmmm it was like [ using the Sherlock Holmes microscope]) lol Very interesting: because we have declared only two parameters (lower and higher) we had specified the length of the array (char *argv[]) . And here argc = 3 , the second argument = lower and the third = higher. It actually works with return (-1) instead of exit(-1) --------------------------------------------------------------------------------------------- #include #include int main(int argc, char *argv[]) { if(argc != 3) { printf("Two args required! "); //exit(-1); return (-1); } int i; int lower; int higher; lower = atoi(argv[1]); higher = atoi(argv[2]); i = lower; printf("argc = %d ", argc); printf("argv[1] = %s ", argv[1]); printf("argv[2] = %s ", argv[2]); while(i
@PortfolioCourses
@PortfolioCourses 2 года назад
Yep, return -1 will work too!
@zoquevil4792
@zoquevil4792 2 года назад
@@PortfolioCourses Very useful when you want to test your code many times with other cases for instance without rewriting all the code just by passing the arguments on the command line because the code is already compiled! As you said, and at the end of the day, it will be easier to improve the behavior of the program much much faster 💪
@Stophidinginthecomments
@Stophidinginthecomments 9 месяцев назад
What does exit(-1) mean?
@PortfolioCourses
@PortfolioCourses 9 месяцев назад
exit(-1) will stop the program with an exit status of -1, which signifies something is wrong :-)
@PortfolioCourses
@PortfolioCourses 9 месяцев назад
This video may be helpful: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-8RucxSeAemw.html :-)
@user-cu3sp4tm3u
@user-cu3sp4tm3u 4 месяца назад
900th like
Далее
Recursion | C Programming Tutorial
10:49
Просмотров 26 тыс.
What are command line arguments (argc and argv)?
11:38
Просмотров 116 тыс.
how Google writes gorgeous C++
7:40
Просмотров 832 тыс.
Function Pointers | C Programming Tutorial
18:31
Просмотров 57 тыс.
Learn Any Programming Language In 3 Hours!
22:37
Просмотров 285 тыс.
why do header files even exist?
10:53
Просмотров 381 тыс.
What does int argc, char* argv[] mean?
10:11
Просмотров 350 тыс.
МОЖЕТ ЛИ УКУСИТЬ СОБАКА
0:14
Просмотров 3 млн