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
Good to see you back man, missed your videos
keep going bro you are doing such a great work
Thanks for video! It is good that you are back!
Thank you for your helpful explanation, your videos always help me
Good to see you again
Thanks big time 💯
I needed this 3 days ago, it was in my final exam lol
Damn... sorry for being late
@@CodeVault dont worry, all your other videos have helped me a lot for this exam.
Please do C++ too, class and other stuff only unique to C++
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)".
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)"
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
comment afficher le statut de retour d’appel de la commande shell
how can i implement my own my_getevn function which will will work exactly like this ?
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
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{$_}."\'", "
"}
I haven't worked with Perl before but I noticed a lot of the Linux libraries use it
@@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.