How to get environment variables in C

Поділитися
Вставка
  • Опубліковано 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

  • @hanaksi
    @hanaksi Рік тому

    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 7 місяців тому

    Thanks big time 💯

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

  • @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 9 місяців тому

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

  • @Patriko30
    @Patriko30 4 місяці тому

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

    • @CodeVault
      @CodeVault  2 місяці тому

      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.