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

时间:2017-04-04 07:51:54

标签: c windows spawn

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

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

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

1 个答案:

答案 0 :(得分:5)

你错过了作为参数列表的一部分传递的终止NULL。

如果没有该终结符,参数列表的末尾将不会被识别,系统将继续读取,因为访问了无效的内存位置而导致undefined behavior