我正在测试一个程序“myprog.c”,如果它使用任何输入参数运行就会崩溃:
#include <stdlib.h>
int main(int argc, char * arg[]){
if (argc > 1 ){
abort();
}
}
正如预期的那样,“./myprog.out abc”崩溃了。但后来我试图从一个文件中获取输入:“./myprog.out <inputs.txt”,其中inputs.txt有几个词,程序不会崩溃。为什么不?
那是因为 shell 不< inputs.txt
作为参数传递。相反,shell 使它inputs.txt
能够从stdin
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句