What are command line arguments (argc and argv)?

Поделиться
HTML-код
  • Опубликовано: 19 окт 2024

Комментарии • 77

  • @alricboullemant3117
    @alricboullemant3117 3 года назад +46

    hello great video as always, I would just like to point out for anyone who wants to pass a string containing a space inside of it as an argument, the command line doesn't actually split by spaces (4:26), you can actually use speech marks like this: Tutorial.exe test "test2 and test3" test4
    And this would return
    argv[0]: Tutorial.exe
    argv[1]: test
    argv[2]: test2 and test3
    argv[3]: test4

  • @srinivasanc1537
    @srinivasanc1537 3 года назад +43

    Very useful video....especially I like last few minutes about where these command line arguments are getting used in reality.... Keep up the good work

  • @pablomolero3856
    @pablomolero3856 2 года назад +13

    Thank you SO MUCH for this video. As a first semester computer engineering student, videos like this are SO freaking valuable to noobs like me. The fact that you are uploading such interesting and well explained videos should be acknowledge. Thank you so much, good sir.

  • @DimitriosCharalampidis
    @DimitriosCharalampidis 2 года назад +6

    I like the way you explain, step by step in a coding environment, instead of doing so only theoretically. Your videos really helped me. Thanks and keep it up!

  • @isagumus1
    @isagumus1 6 месяцев назад

    You definitely know what you are doing and spreading confidence when you are explaining. Thank you so much for such a clear and fluent explanation!

  • @Lexyvil
    @Lexyvil 2 года назад +1

    The best explanation I've seen on this topic, that seems so cryptic to learn anywhere else.

  • @TheLostCrusader.
    @TheLostCrusader. Год назад +5

    Your channel is Babel's library for computer science students

  • @shaboobis9283
    @shaboobis9283 2 года назад

    My friend you are simply an excellent teacher. I am very appreciative of these C tutorials. I have purchased a C course on Udemy which happens to be taught by another Italian guy. Between the two of you I will be fluent in no time.

  • @julianrochacz9100
    @julianrochacz9100 Год назад

    One of the greatest educators on this platform hands down.

  • @ezcomander
    @ezcomander 3 года назад +1

    Omg, I've been pulling hairs trying to understand what's going on. Thank you!!!

  • @AlgoAntics
    @AlgoAntics 4 года назад +1

    bro seriously when i saw you first time i was like you have million subscriber but when i saw your subs it really didn't matched post video more frequently you'll quickly get more subscriber you are so good

  • @joeyhanni6855
    @joeyhanni6855 8 месяцев назад

    Very well explained ,this has been quite useful ,I keep coming back now

  • @oviya.n1317
    @oviya.n1317 3 года назад

    Thank u so so much sir. Preparing for my interview's first round at multicoreware and this helped me so much. Love from INDIA ❤️🇮🇳

  • @jeshuruncarlos6649
    @jeshuruncarlos6649 4 года назад +1

    I Just Want To Thank You And Keep Doing What You Are Doing !
    You Will Be Of Great Help To A Lot Of People,As You Are Now !

  • @ALLIN-dc5my
    @ALLIN-dc5my 4 года назад +2

    I am will comment in your every video you just continue 🙏 making that lovely content my friend.

  • @priyavartrajain2166
    @priyavartrajain2166 3 года назад +1

    Thank you for providing such knowledgeable content !

  • @hoangt4182
    @hoangt4182 5 месяцев назад

    really solid and easy to understand sir, thanks for you tutorial

  • @madsecond5025
    @madsecond5025 11 месяцев назад

    Beautiful tutorial. Explained perfectly thank you so much.

  • @Lawton407
    @Lawton407 2 года назад

    You're the goat. You explain everything so clearly, thank you.

  • @ninjacncrazy6910
    @ninjacncrazy6910 Год назад

    this video was very helpful when I was doing my cs homework
    thank you :)

  • @sangnguyenn2367
    @sangnguyenn2367 2 года назад

    Awww your tutorial is really easy to understand

  • @taqueritovaquerito
    @taqueritovaquerito 3 года назад

    thank you for all the videos, they have really helped me a lot

  • @skarabayev
    @skarabayev 4 года назад +2

    Thanks a lot! Very clear and simple.

  • @wscamel226
    @wscamel226 Год назад +2

    very very helpfull thank you - thought even with that I had some problems because I tried to pass via cmd name of the file that the program would use but for whatever reason it didn't work and after like 10h I realised that the files aren't where the .exe is so I needed to send their full path to them instead of just the name of the file

  • @iskandar149
    @iskandar149 4 года назад +1

    continue making thas awesome content, love it. talk about pointers please

  • @urosjankovic1509
    @urosjankovic1509 3 года назад +1

    Thank you for your explanation :)

  • @mikediaz9033
    @mikediaz9033 2 года назад

    Clear and Concise.
    Thankyou

  • @aditisahu8005
    @aditisahu8005 10 месяцев назад

    very helpful video. Thank you so much.

  • @parisa9374
    @parisa9374 2 года назад

    May you please make a session explaining the concept of the command-line argument as the concept of double-pointer and how to use it in a function call?

  • @GabrielMirandaLima-hv7oe
    @GabrielMirandaLima-hv7oe 11 месяцев назад

    there more I learn c the more I love it

  • @durzua07
    @durzua07 4 года назад +5

    So helpful! I have a question though, how do you set global variables based on command line arguments? Thank you!

    • @CodeVault
      @CodeVault  4 года назад +3

      Just declare it global and set it in main, something like this, but maybe with more validation for converting the argv elements to the needed type:
      int globalVar;
      int main(int argc, char* argv[]) {
      if (argc > 1) {
      globalVar = (int) strtol(argv[1], NULL, 0);
      }
      }

  • @abuanas4430
    @abuanas4430 7 месяцев назад

    Very clear, you deserve "like" and subscribe

  • @aigallery1406
    @aigallery1406 3 года назад

    Very helpful and very unique content ❤️

  • @Ethan-rw7ub
    @Ethan-rw7ub 4 года назад

    clear and concise! great video!

  • @berktopbas1496
    @berktopbas1496 3 года назад +1

    I wrote the exact same code, tried it on Win 10 and VM Linux Ubuntu with different IDEs and editors(CodeLite and VS Code) and with different compilers(MinGW64, gcc, clang). They build without errors and warnings, and when i don't pass any integer into command line all is good - result = 1. But when i pass some integers, either program crashes on Win 10 or i get result = 0 on Ubuntu . But argv's at the begining print correctly. On the debug session with CodeLite, i get error "Program received signal SIGSEGV" on the line where x is assigned using strtol function. Having a hard time to get it..

    • @CodeVault
      @CodeVault  3 года назад

      Huh... can you share the code please? I can look into it

  • @iasonastzene9151
    @iasonastzene9151 2 года назад

    this helped me a lot thnx for explaining :)

  • @venkatrahulyadav6068
    @venkatrahulyadav6068 4 года назад +1

    But in printf argv[i] when we are using it is giving the address of the string why are we not using * in front of argv[i]?

    • @CodeVault
      @CodeVault  4 года назад +3

      argv is an array of pointers to char. argv[i] gets the i-th element in that array and dereferences it leaving us with a pointer to char (which is considered a string).
      argv[i] is short-hand for *(argv + i) so, in fact, we are using *

  • @pratyushkumar3829
    @pratyushkumar3829 3 года назад +1

    Can we also use atoi() instead of strtol() for converting string to int?

    • @CodeVault
      @CodeVault  3 года назад +1

      No. It has a lot of issues. I really suggest you use strtol. I have some videos regarding that: code-vault.net/lesson/ppdf96xhwi:1603733526989

  • @toi_let954
    @toi_let954 Год назад

    My program will not allow me to pass in command line arguments. Is there something wrong with my compiler?

    • @CodeVault
      @CodeVault  Год назад

      How are you running your program?

  • @SRNSHRDDY
    @SRNSHRDDY 4 года назад

    Keep it going very helpful

  • @eduardoschiavon5652
    @eduardoschiavon5652 4 года назад +1

    Great Video!
    Do you know if it's possible to debug on codeblocks while using command line arguments? I haven't been able to do it.

    • @CodeVault
      @CodeVault  4 года назад +2

      In the top bar: Project -> Set programs' arguments. Make sure you add them to the proper target (most likely Debug).

  • @hansonchen6491
    @hansonchen6491 2 года назад

    Hi there: thank you for your video! It is truly very useful. Yet I have two questions remain: First, since argc is in the argument, why don't we need to input an integer in the command line? Since technically the main function has two inputs: the integer argc and the string array argv, right? Second, is there other ways to do command line argument other than int main( int argc, char* argv[]) ? What I mean is, is this argument a convention and never should have been changed? Is it possible if, let's say I write int main(int a, int b) ? Thank you!

    • @CodeVault
      @CodeVault  2 года назад

      1) You don't need to type the value of argc in the command line because the command line processor takes care of that for you
      2) Yes, it's a convention and there really isn't any other way of doing it (that's not hacky at least)

    • @hansonchen6491
      @hansonchen6491 2 года назад

      @@CodeVault Thank you so much for your explanation! It's truly very helpful.

  • @fellowkrieger457
    @fellowkrieger457 8 месяцев назад

    Perfect example thx.

  • @fsociety401
    @fsociety401 Год назад

    hey thank you for the great content, your videos are really helpful.
    I have two questions, what is the best way to convert an int array to array of strings char* newargv [] so I can pass it to a new program using execve() system call, could I use type casting to do it and is using sprintf() a good way of doing it.
    The second questions is it possible to pass arguments from parent process to the child process using execve(), my professor is asking us to do it for the assignment and I can't find any useful source about this, I know that you should use a pipe to share data between process but our professor want us to do it using execve().
    Thank you alot for the time and help.

    • @CodeVault
      @CodeVault  Год назад +2

      1) You can't use type casting for it. sprintf() used in a loop is a good solution though
      2) There are these videos regarding your question:
      code-vault.net/course/46qpfr4tkz:1603732431896/lesson/43zvcsz6o1:1603732432539
      code-vault.net/course/46qpfr4tkz:1603732431896/lesson/phac6gv4cy:1603733529763

  • @goktugparlak1618
    @goktugparlak1618 Год назад

    my programme gives always this error how can I fix it I can not write a argument on terminal The term 'a' is not recognized as the name of a cmdlet

    • @CodeVault
      @CodeVault  Год назад

      "a" is the name of your executable?

  • @mr.nothing7058
    @mr.nothing7058 Год назад

    Great sir.
    Sir can we create a GUI by using C.

    • @CodeVault
      @CodeVault  Год назад

      Yes, of course. Here's the documentation for Win32 API for Windows: learn.microsoft.com/en-us/windows/win32/apiindex/windows-api-list

  • @JasonKT13
    @JasonKT13 4 года назад

    pretty useful thanks, keep it up!

  • @ALLIN-dc5my
    @ALLIN-dc5my 4 года назад

    You are the best bro keet it up I subscribed

  • @DASOFILAX
    @DASOFILAX 3 года назад

    lets say i want to pass a txt file as an argument through terminal. Do i follow the same procedure?

    • @CodeVault
      @CodeVault  3 года назад

      Yea, you'll have the path of the file at argv[1]

  • @VietPhan-ex3ps
    @VietPhan-ex3ps 4 месяца назад

    thank you so much

  • @freewillimusic
    @freewillimusic Год назад

    sorry what ide are you using?

    • @CodeVault
      @CodeVault  Год назад

      In this video I'm using Visual Studio Community Edition

  • @rajkaransinghgill2082
    @rajkaransinghgill2082 Год назад

    why tutorial.exe is first argument when your file name is main.c ?

    • @CodeVault
      @CodeVault  Год назад

      That's just how Visual Studio compiles the project. The executable is the name of the project, which, in my case, is "Tutorial"

  • @Tech_Eshwar
    @Tech_Eshwar 2 года назад

    all that I can say is...thank you so much bruh

  • @gioyose
    @gioyose 4 года назад +1

    so helpful, thank you!!!!

  • @lokkrip
    @lokkrip 3 года назад

    great video thank you very much you beautiful fella :)

  • @maxim25o2
    @maxim25o2 4 года назад

    You said that this is c++ programming, but why you use commands from C?

    • @CodeVault
      @CodeVault  4 года назад +1

      That's just for explanation, you can use C++ functions (like cout) if you want to. This video focuses on argc and argv and what they contain.

  • @Ellefsen97
    @Ellefsen97 Год назад

    Ahh so that’s what string[] args is

  • @YuhIoLLL
    @YuhIoLLL 7 месяцев назад

    Cool 🎉

  • @sangnguyenn2367
    @sangnguyenn2367 2 года назад

    Xin cảm ơn

  • @sangnguyenn2367
    @sangnguyenn2367 2 года назад

    🥰🥰🥰🥰🥰🥰🥰🥰🥰

  • @sangnguyenn2367
    @sangnguyenn2367 2 года назад

    😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘

  • @AndrewChapman-j6p
    @AndrewChapman-j6p 8 месяцев назад

    Sank yu