我需要为 C 项目使用环境变量,所以我在终端中执行了此操作:
export FILE_CONFIG="/home/pc/file.conf"
file.conf是我创建的文件。
如果我env
在终端中这样做,我可以在列表中看到“FILE_CONFIG”及其值(/home/pc/file.conf)。我想在.C程序中分配给path_to_config -> /home/pc/file.conf SO,我这样做了:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
char* path_to_config = getenv("FILE_CONFIG");
但是getenv
不会返回 FILE_CONFIG 的路径。当我在调试模式下查看时 path_to_config 值是 0x0。我已经尝试过使用其他环境变量,但我无法使用我导出的这个变量。