Тёмный

Getting Command-Line Arguments in C 

Jacob Sorber
Подписаться 161 тыс.
Просмотров 61 тыс.
50% 1

Patreon ➤ / jacobsorber
Courses ➤ jacobsorber.thinkific.com
Website ➤ www.jacobsorber.com
---
Getting Command-Line Arguments in C // Another beginner C video, this one shows you how to handle command-line arguments passed into your program from the terminal.
String videos:
• Strings in C
• Reversing Strings (in ...
About pointers and arrays:
• Learning C: Basic Type...
• Arrays, Pointers, and ...
• Making Peace with Doub...
***
Welcome! I post videos that help you learn to program and become a more confident software developer. I cover beginner-to-advanced systems topics ranging from network programming, threads, processes, operating systems, embedded systems and others. My goal is to help you get under-the-hood and better understand how computers work and how you can use them to become stronger students and more capable professional developers.
About me: I'm a computer scientist, electrical engineer, researcher, and teacher. I specialize in embedded systems, mobile computing, sensor networks, and the Internet of Things. I teach systems and networking courses at Clemson University, where I also lead the PERSIST research lab.
More about me and what I do:
www.jacobsorber.com
people.cs.clemson.edu/~jsorber/
persist.cs.clemson.edu/
To Support the Channel:
+ like, subscribe, spread the word
+ contribute via Patreon --- [ / jacobsorber ]
+ rep the channel with nerdy merch --- [teespring.com/stores/jacob-so...]
Source code is also available to Patreon supporters. --- [jsorber-youtube-source.heroku...]
Want me to review your code?
Email the code to js.reviews.code@gmail.com. Code should be simple and in one of the following languages: C, C++, python, java, ruby. You must be the author of the code and have rights to post it. Please include the following statement in your email: "I attest that this is my code, and I hereby give Jacob Sorber the right to use, review, post, comment on, and modify this code on his videos."
You can also find more info about code reviews here.
• I want to review your ...

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

 

27 июн 2019

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 65   
@chriswaggoner4691
@chriswaggoner4691 4 года назад
I love how you identify stumbling blocks and quickly go over the basics nobody else bothers with. Wish I had had your videos 20 years ago!
@JacobSorber
@JacobSorber 4 года назад
Thanks.
@I_Like_Dimsum
@I_Like_Dimsum 3 года назад
Such a needed video. We need these kind of short and concise videos man
@victorcercasin
@victorcercasin 4 года назад
great video! Even though you hurt me in the soul a little by calling me a beginner. It is true, of course
@JacobSorber
@JacobSorber 4 года назад
Thanks. I hope your soul heals. We're all just travelers somewhere on the road. 😀
@myrajarenga9432
@myrajarenga9432 Год назад
Really helpful and helped me understand argv and argc better. Thank you
@namewithheld9800
@namewithheld9800 4 года назад
Well explained and easily understandable which is rare.
@MrBrancomusic
@MrBrancomusic 3 года назад
Just started cs50 and could not understand command line arguments,this helped me a lot! Thank you!
@manoharpanwar1265
@manoharpanwar1265 5 лет назад
Thanks Jacob, it's really helpful
@zihangjin9186
@zihangjin9186 2 года назад
Clean and efficient, thank you!
@fergespacalovits479
@fergespacalovits479 2 года назад
Very good and really helpful tutorial thanks a lot:)
@rivkas2224
@rivkas2224 2 года назад
Thank you so clear and simple! Thank you
@robertwitt1276
@robertwitt1276 3 года назад
Awesome video thanks a ton man keep up the good work
@guieguima
@guieguima 5 лет назад
Awesome helpful video! :)
@toddschmieder7873
@toddschmieder7873 2 года назад
Holy cow! That was awesome! Thank you!
@joeman677
@joeman677 5 месяцев назад
Wonderful video with a great example to help illustrate its function thanks a ton!
@mow3890
@mow3890 5 лет назад
thanks, jacob
@CruiserAlong
@CruiserAlong 2 года назад
thank you....grt explanation
@user-hm2uw1qt1s
@user-hm2uw1qt1s Год назад
Helpful video, thanks 👍
@cryptic_daemon_
@cryptic_daemon_ Год назад
I actually cant believe id did not use this in my coding classes. ty sm!!
@yourtubepk
@yourtubepk Год назад
Great video👍
@nithinpajayan3006
@nithinpajayan3006 2 года назад
You are the best. period.
@jaxondowning2004
@jaxondowning2004 2 года назад
Hey brother Sorber! I don't know if you remember me but I served part of my mission in your area towards the end of 2018 and beginning of 2019. You talked to me about the difference in computer engineering and software engineering and convinced me to pursue a degree in software engineering. I happened to stumble on this video as I'm trying to quickly learn C for a project in my computer networks class. I hope all is well!
@JacobSorber
@JacobSorber 2 года назад
Hi Jaxon. It's good to hear from you. My memory of that conversation is a bit fuzzy, but I hope software engineering treats you well. And, yes, we're doing well.
@robertnelson2720
@robertnelson2720 Год назад
Could you go into more detail in another video on the command line? Like how to make a command utility, run multiple programs using the command utility, and to pass args to a second prog?
@tomasvalent4405
@tomasvalent4405 3 года назад
Can I change value of argc or argv? I saw something like that in CodeBlocks, they add some numbers there and argc or argv can write them out. (I use dev cpp)
@jayarajdavid
@jayarajdavid 4 года назад
This helped me a lot! Thanks
@JacobSorber
@JacobSorber 4 года назад
You're welcome.
@fontanot
@fontanot 3 года назад
thank you, now i got it :)
@bikki60
@bikki60 4 года назад
how can i use argv to trigger different methods e.g. "anapp dostuff" returns "doing stuff"
@amos660
@amos660 Год назад
How do you pass command line arguments to a function that is in a different C file? you just call that function from the main? does anyone know? I can't figure it out...
@user-uj5pc7dy2j
@user-uj5pc7dy2j 3 года назад
Hello, I just found you through this video and, from a glance at your channel, I see that you make videos on just what I am passionate about: low-level languages, embedded systems and hardware... well, I *had to* subscribe!! :p haha. Anyway, thank you for sharing your knowledge! Greetings from Argentina.
@JacobSorber
@JacobSorber 3 года назад
Welcome! Glad you found the channel.
@Alexis_Lynna
@Alexis_Lynna 4 года назад
What text editor are you using ? Also if you run a file with a text document piped in like “ ./a.out < file.txt “ do you have to open the file or can you simply loop through the file and store data as needed ?
@JacobSorber
@JacobSorber 4 года назад
I think I was using VS Code for this one. I also occasionally use atom. And, if you pipe in a file, like that, you don't have to open it. Just read the contents from stdin.
@Uerdue
@Uerdue 2 года назад
Oh, "ASCII to int". That's what that weird, mysterious `atoi` is supposed to mean! Thanks, never knew that! :D
@activelivingchallenger4298
@activelivingchallenger4298 4 года назад
How do i incorporate this with a make file? I'd like to do something like: make argName. Is there a way to get argv as a variable of some kind for the make file?
@JacobSorber
@JacobSorber 4 года назад
You can do something like this. make target MYVARIABLE=value ...and then in the makefile, you can use $(MYVARIABLE). That's how I've seen it typically done. I don't think you can get the raw argv, but I could be wrong.
@100taeh3
@100taeh3 3 года назад
Hello sir! I'm taehee from South Korea! thanks for great video! There's one thing I'd like to know about argc and argv. It might be further question from this video content! But I'd like to know how main function get "what I type in on the command line"...! like how....! or like how it works!! Is there any video that I might wanna watch to answer this question? or can you explain this for me?? thanks sir!
@NateROCKS112
@NateROCKS112 2 года назад
To my knowledge (not much), this is how it works. When the shell executes a program, it forks itself, and then it pushes argv[] and argc to the stack, in that order, and it allocates memory for each argument. Then it calls execve on the program name. So the stack looks, in reverse order, like "argc argv[0] argv[1] argv[2] ...". argv[0], for instance, is the memory address of the program name (in C, of type char*).
@subliminalcastillo2126
@subliminalcastillo2126 3 года назад
Damn that music that plays at 00:10 was funky as hell. It made me wanna put on my pizza guy outfit, knock on that rich lady in the bathrobe's doors, come on inside and..
@metl_play
@metl_play Год назад
Okay, I got that so far, but how can I compare like argv[1] with a string? As abc in argv ist not "abc". Because '''if (argv[1] == "abc"){....}''' will not be true if I run: argv.exe abc EDIT: It is ofc because I need to do a string compare with strcmp()
@justcurious1940
@justcurious1940 Год назад
I can't print them directly
@ttc0419
@ttc0419 5 лет назад
Great video, could you made a video about how to use getopt() and getopt_long()?
@JacobSorber
@JacobSorber 5 лет назад
Sure. I'll add it to the list. Just need to find time. :)
@SuperCape
@SuperCape 5 лет назад
@@JacobSorber I got you covered: in glibc time() is declared inside the time.h header and defined inside time.c 😎
@JacobSorber
@JacobSorber 5 лет назад
You're a life saver! Thank you.
@SuperCape
@SuperCape 5 лет назад
Qwestian: - Say I have a UTF terminal in Linux (fug aple) - Say I pass an EMOJI as an arg - What do I get in my string? - Shouldn't all the characters be UTF rather than ASKYBOI?
@JacobSorber
@JacobSorber 5 лет назад
Unicode and UTF-8 are on my list of things to make future videos about. Short answer is you can store your characters as chars, and then interpret them as UTF-8, or you can convert them to wide characters. There are a few different ways to handle things. I'll try to give a better explanation in the future, but for now, try it out. Pass in the emoji in UTF-8 and then look at the bytes that are passed in (using a debugger). Your standard ASCII characters will all just be 1 byte. The emoji or other non-ASCII characters will be encoded with more bytes.
@SuperCape
@SuperCape 5 лет назад
@@JacobSorber so, I've arranged this piece of code: #include #include int main (int argc, char** argv){ int i,j; for (i=1; i
@JacobSorber
@JacobSorber 5 лет назад
@@SuperCape You should look at the UTF-8 encoding. It uses a variable number of bytes per character. So, it is all UTF-8. The first 128 UTF characters just happen to be the same as the ASCII set.
@southmcwow
@southmcwow 2 года назад
I’m the most literal definition of beginner there is. Im doing cs50 and am currently struggling big time. Im just having a terrible time actually getting the concepts. Im on this video because im working on the prescribed Caesar problem set that utilizes command line arguments. Im curious what the “[i]” means after argv in the printf statement and when to use it.
@JacobSorber
@JacobSorber 2 года назад
Welcome and good luck. Don't let the details get overwhelming. argv is an array of strings (char *). argv[0] tells it to get the first string. argv[1] tells it to get the second string. argv[i] tells it to get the i-th string. I hope that helps.
@southmcwow
@southmcwow 2 года назад
@@JacobSorber It does, but I'm not sure what you mean when you say i-th string. If I had to use my brain in a logical way, I'd say it represents values like tenth, eleventh, twelfth, etc. So anything after 0-9? Do I have that right?
@JacobSorber
@JacobSorber 2 года назад
@@southmcwow Yeah. Say that i is a number (12), then argv[i] is argv[12], which is string #12. Just remember that array indexing starts at 0.
@arkadymagomedov1700
@arkadymagomedov1700 2 года назад
getopt is in order
@JacobSorber
@JacobSorber 2 года назад
I agree. I'll see what I can do about that. 😀
@hellNo116
@hellNo116 3 года назад
i find it hilarious i forgot what that meant in less than a semester....
@paulhetherington3854
@paulhetherington3854 2 года назад
I.e. Linux -- never windowsz.
@gnaneshwaar2594
@gnaneshwaar2594 4 года назад
So basically, its a like comment.?
@jhongzhun1832
@jhongzhun1832 2 года назад
this is too fast for me
@behrad7476
@behrad7476 2 года назад
it wasnt help full :(
@didiTchu
@didiTchu 2 года назад
too fast, lack of explanation
@9700784176
@9700784176 5 месяцев назад
in my text book it is like this char argv* [ ] but you written like this, char **argv what's is the difference??
Далее
Learn make in 60 seconds.
2:08
Просмотров 102 тыс.
What are command line arguments (argc and argv)?
11:38
Просмотров 116 тыс.
Header Issues: Guards, Name Mangling, and extern "C"
8:32
why are switch statements so HECKIN fast?
11:03
Просмотров 393 тыс.
Making variables atomic in C
11:12
Просмотров 36 тыс.
What does int argc, char* argv[] mean?
10:11
Просмотров 350 тыс.
Defining Constants. Should I use CONST or #DEFINE?
7:59