Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 为什么可以';我不能打印传递给程序的第一个参数吗?_C_Bash_Arguments - Fatal编程技术网

C 为什么可以';我不能打印传递给程序的第一个参数吗?

C 为什么可以';我不能打印传递给程序的第一个参数吗?,c,bash,arguments,C,Bash,Arguments,我用c编写了一个简单的代码: #include <stdio.h> int main( int argc, char* argv[] ) { printf( "Hello, just wanted to say: %s.\n", argv[1] ); return 0; } 放入%s的输出是(null),而不是预期的“Hello”。为什么?你似乎误解了管道的工作原理。当您像以前那样使用管道时,app1的输出用作app2的stdin,而不是app2的命令行参数 是这样

我用c编写了一个简单的代码:

#include <stdio.h>
int main( int argc, char* argv[] ) {
    printf( "Hello, just wanted to say: %s.\n", argv[1] );
    return 0;
}

放入
%s
的输出是
(null)
,而不是预期的“Hello”。为什么?

你似乎误解了管道的工作原理。当您像以前那样使用管道时,
app1
的输出用作
app2
stdin
,而不是
app2
的命令行参数

是这样的:

stdin->app1->stdout >----------> stdin->app2->stdout
                        pipe

您看到的是
/app2
的输出
/app1
的输出与示例命令无关
stdin->app1->stdout >----------> stdin->app2->stdout
                        pipe