What are command line arguments (argc and argv)?

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ม.ค. 2025

ความคิดเห็น • 79

  • @srinivasanc1537
    @srinivasanc1537 3 ปีที่แล้ว +45

    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

  • @alricboullemant3117
    @alricboullemant3117 3 ปีที่แล้ว +53

    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

  • @DimitriosCharalampidis
    @DimitriosCharalampidis 3 ปีที่แล้ว +7

    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!

  • @pablomolero3856
    @pablomolero3856 3 ปีที่แล้ว +14

    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.

  • @Lexyvil
    @Lexyvil 2 ปีที่แล้ว +1

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

  • @isagumus1
    @isagumus1 9 หลายเดือนก่อน

    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!

  • @TheLostCrusader.
    @TheLostCrusader. 2 ปีที่แล้ว +7

    Your channel is Babel's library for computer science students

  • @julianrochacz9100
    @julianrochacz9100 ปีที่แล้ว

    One of the greatest educators on this platform hands down.

  • @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

  • @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 !

  • @joeyhanni6855
    @joeyhanni6855 ปีที่แล้ว

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

  • @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.

  • @Lawton407
    @Lawton407 2 ปีที่แล้ว

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

  • @ALLIN-dc5my
    @ALLIN-dc5my 5 ปีที่แล้ว +2

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

  • @ezcomander
    @ezcomander 3 ปีที่แล้ว +1

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

  • @priyavartrajain2166
    @priyavartrajain2166 4 ปีที่แล้ว +1

    Thank you for providing such knowledgeable content !

  • @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 ❤️🇮🇳

  • @taqueritovaquerito
    @taqueritovaquerito 3 ปีที่แล้ว

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

  • @hoangt4182
    @hoangt4182 8 หลายเดือนก่อน

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

  • @ninjacncrazy6910
    @ninjacncrazy6910 2 ปีที่แล้ว

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

  • @madsecond5025
    @madsecond5025 ปีที่แล้ว

    Beautiful tutorial. Explained perfectly thank you so much.

  • @skarabayev
    @skarabayev 4 ปีที่แล้ว +2

    Thanks a lot! Very clear and simple.

  • @sangnguyenn2367
    @sangnguyenn2367 2 ปีที่แล้ว

    Awww your tutorial is really easy to understand

  • @Stoh
    @Stoh 2 หลายเดือนก่อน

    Phenomenal video, thank you.

  • @urosjankovic1509
    @urosjankovic1509 3 ปีที่แล้ว +1

    Thank you for your explanation :)

  • @mikediaz9033
    @mikediaz9033 2 ปีที่แล้ว

    Clear and Concise.
    Thankyou

  • @iskandar149
    @iskandar149 4 ปีที่แล้ว +1

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

  • @aditisahu8005
    @aditisahu8005 ปีที่แล้ว

    very helpful video. Thank you so much.

  • @abuanas4430
    @abuanas4430 10 หลายเดือนก่อน

    Very clear, you deserve "like" and subscribe

  • @aigallery1406
    @aigallery1406 3 ปีที่แล้ว

    Very helpful and very unique content ❤️

  • @GabrielMirandaLima-hv7oe
    @GabrielMirandaLima-hv7oe ปีที่แล้ว

    there more I learn c the more I love it

  • @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

  • @Ethan-rw7ub
    @Ethan-rw7ub 4 ปีที่แล้ว

    clear and concise! great video!

  • @iasonastzene9151
    @iasonastzene9151 2 ปีที่แล้ว

    this helped me a lot thnx for explaining :)

  • @SRNSHRDDY
    @SRNSHRDDY 4 ปีที่แล้ว

    Keep it going very helpful

  • @fellowkrieger457
    @fellowkrieger457 11 หลายเดือนก่อน

    Perfect example thx.

  • @JasonKT13
    @JasonKT13 4 ปีที่แล้ว

    pretty useful thanks, keep it up!

  • @ALLIN-dc5my
    @ALLIN-dc5my 5 ปีที่แล้ว

    You are the best bro keet it up I subscribed

  • @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?

  • @VietPhan-ex3ps
    @VietPhan-ex3ps 7 หลายเดือนก่อน

    thank you so much

  • @Tech_Eshwar
    @Tech_Eshwar 2 ปีที่แล้ว

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

  • @gioyose
    @gioyose 4 ปีที่แล้ว +1

    so helpful, thank you!!!!

  • @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);
      }
      }

  • @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

  • @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

  • @lokkrip
    @lokkrip 3 ปีที่แล้ว

    great video thank you very much you beautiful fella :)

  • @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 *

  • @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).

  • @fsociety401
    @fsociety401 2 ปีที่แล้ว

    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 ปีที่แล้ว +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

  • @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

  • @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?

  • @YuhIoLLL
    @YuhIoLLL 10 หลายเดือนก่อน

    Cool 🎉

  • @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?

  • @WilliRichMusic
    @WilliRichMusic ปีที่แล้ว

    sorry what ide are you using?

    • @CodeVault
      @CodeVault  ปีที่แล้ว

      In this video I'm using Visual Studio Community Edition

  • @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.

  • @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]

  • @SasikumarAlvvar
    @SasikumarAlvvar หลายเดือนก่อน

    Danke

  • @rajkaransinghgill2082
    @rajkaransinghgill2082 2 ปีที่แล้ว

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

    • @CodeVault
      @CodeVault  2 ปีที่แล้ว

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

  • @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

  • @sangnguyenn2367
    @sangnguyenn2367 2 ปีที่แล้ว

    Xin cảm ơn

  • @sangnguyenn2367
    @sangnguyenn2367 2 ปีที่แล้ว

    🥰🥰🥰🥰🥰🥰🥰🥰🥰

  • @sangnguyenn2367
    @sangnguyenn2367 2 ปีที่แล้ว

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

  • @AndrewChapman-j6p
    @AndrewChapman-j6p 11 หลายเดือนก่อน

    Sank yu