以下程序崩溃。我做错了什么?
#include <stdio.h>
#include <process.h>
int main() {
puts("Hello!");
return spawnlp(0, "notepad.exe", "notepad.exe", "test.txt");
}
答案 0 :(得分:5)
你错过了作为参数列表的一部分传递的终止NULL。
如果没有该终结符,参数列表的末尾将不会被识别,系统将继续读取,因为访问了无效的内存位置而导致undefined behavior。