在 C 中生成进程的简单代码崩溃。为什么?

Simple code spawning a process in C crashes. Why?

以下程序崩溃。我做错了什么?

#include <stdio.h>
#include <process.h>

int main() {
    puts("Hello!");
    return spawnlp(0, "notepad.exe", "notepad.exe", "test.txt");
}

您缺少要作为参数列表的一部分传递的终止 NULL。

如果没有该终止符,将不知道参数列表的末尾,系统将继续读取,这会导致 undefined behavior 由于访问无效内存位置。