Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我必须做我的功课,但我不能走 C 的道路。例如;
int main(void) { char *path; path = getenv("PATH"); if(path) printf("The current path is: %s\n", path); return 0; }
如果我运行这段代码,我会得到“分段错误(核心转储)”。我的操作系统是 Ubuntu 14.04 LTS。
添加
#include <stdlib.h>
到列表顶部并尝试一下。它可能是 getenv 到 char * 指针的假定 int 返回,从而导致代码出错。