C语言:读取环境变量

说明

C 语言提供了 getenv() 函数(原型在 stdlib.h )用来读取命令行环境变量。

#include <stdio.h>
#include <stdlib.h>

int main(void) {
  char* val = getenv("JAVA_HOME");

  if (val == NULL) {
    printf("不存在\n");
  }else{
    printf("%s\n", val);
  }
  return 0;
}

原文出处:https://malaoshi.top/show_1IX3TPaBg3lW.html