How to get environment variables in C

Поделиться
HTML-код
  • Опубликовано: 18 янв 2023
  • Source code can be found here:
    code-vault.net/lesson/
    ===== Support us through our store =====
    code-vault.net/shop
    ===== Check out our website =====
    code-vault.net
    ===== Check out our Discord server =====
    discord.code-vault.net

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

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

    Good to see you back man, missed your videos

  • @soufianeamimi
    @soufianeamimi Год назад +4

    keep going bro you are doing such a great work

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

    Thanks for video! It is good that you are back!

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

    Thank you for your helpful explanation, your videos always help me

  • @RDFR-cy4ov
    @RDFR-cy4ov Год назад

    Good to see you again

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

    Thanks big time 💯

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

    Hello sir. First and foremost, I would like to say that your videos are awsome and really helpful. Secondly, I have a question. Correct me if I'm wrong but, when you try to print what's inside of a pointer, you are dereferencing it, right? So why doesn't the program crash when you try to print env_variable at 1:40 ? I believe it shouldn't even print anything besides "segmentation fault (core dumped)".

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

      There's no dereferencing inside the main function when I am calling printf.
      char* env_variable;
      printf("%s
      ", env_variable); // derefencing would be if passed *env_variable
      So, printf gets a pointer and, inside the printf function it probably has a check for NULL so it doesn't dereference the pointer and instead prints out the characters "(null)"

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

      Thank you for answering my question. Im used to seeing my code crash due to passing empty strings to functions so I got confused. When I try to solve the crashes in the debugger, the SIGSEV signal never appears at the function call, but the fact that you can print an empty string still caught me off guard because I've never seen it. Once again, thank you for the explanation

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

    comment afficher le statut de retour d’appel de la commande shell

  • @marksvids1156
    @marksvids1156 Год назад +1

    I needed this 3 days ago, it was in my final exam lol

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

      Damn... sorry for being late

    • @marksvids1156
      @marksvids1156 Год назад +1

      @@CodeVault dont worry, all your other videos have helped me a lot for this exam.

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

    Please do C++ too, class and other stuff only unique to C++

  • @Patriko30
    @Patriko30 3 месяца назад

    how can i implement my own my_getevn function which will will work exactly like this ?

    • @CodeVault
      @CodeVault  Месяц назад

      You could assign envp to some global variable and simply have the function use that. Since envp is a local variable in main, it will never deallocate before the program ends

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

    Do you know that Perl language is a higher level C, it should be by default on every system?
    i.e.: foreach (keys(%ENV)){print $_,"=", "\'".$ENV{$_}."\'", "
    "}

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

      I haven't worked with Perl before but I noticed a lot of the Linux libraries use it

    • @vilijanac
      @vilijanac Год назад +1

      @@CodeVault Yes it is beautiful, works so close with C and libraries.
      You don't worry about types and memory management, has even own garbage collection, fast but is only an on the go interpreter.
      On modern computers don't need to worry about that this much as being slower or less efficient.
      It is better to concentrate on your algorithm, and also find if possible modules already providing what you need, so do not reinvent the wheel.