Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.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_File_Command Line_Io - Fatal编程技术网

在C中从命令行管道传输文件

在C中从命令行管道传输文件,c,file,command-line,io,C,File,Command Line,Io,我需要以以下方式从命令行访问提供给程序的文件:/myProgram1?fopen(argv[1],“r”):标准输入法,然后fgets(…,…,fp)。除非您使用特殊的shell,否则该文件应该能够从标准输入读取。因此类似file*input=stdin的内容?只需编写程序从stdin读取即可。您不必关心stdin输入是来自某个人键入的还是来自某个文件的重定向。也就是说,您可以使用任何能够从stdin读取的函数。e、 g.scanf或fgets(..,..,stdin)等。完美!谢谢你的帮助!或

我需要以以下方式从命令行访问提供给程序的文件:
/myProgram

我想您可以使用命令行参数(argv和argc)来实现这一点,但现在意识到情况并非如此。我只是想知道这个文件输入到哪里(名称或其他),以便我可以访问它


提前谢谢

如果您在unixshell(zsh、bash等)中,如果您在unixshell(zsh、bash等)中,请执行类似于
/myProgram的操作并执行类似于
/myProgram的操作,除非您使用特殊的shell,否则文件应该能够从标准输入读取。因此,按照
file*input=stdin
?只需编写程序从
stdin
读取即可。您不必关心stdin输入是来自某个人键入的还是来自某个文件的重定向。也就是说,您可以使用任何能够从stdin读取的函数。e、 g.
scanf
fgets(..,..,stdin)
等。完美!谢谢你的帮助!或者,您可以从文件中读取,或者从
stdin
(默认情况下),
file*fp=argc>1?fopen(argv[1],“r”):标准输入法
,然后
fgets(…,…,fp)
。除非您使用特殊的shell,否则该文件应该能够从标准输入读取。因此类似
file*input=stdin
的内容?只需编写程序从
stdin
读取即可。您不必关心stdin输入是来自某个人键入的还是来自某个文件的重定向。也就是说,您可以使用任何能够从stdin读取的函数。e、 g.
scanf
fgets(..,..,stdin)
等。完美!谢谢你的帮助!或者,您可以从文件中读取,或者从
stdin
(默认情况下),
file*fp=argc>1?fopen(argv[1],“r”):标准输入法
,然后
fgets(…,…,fp)
#include <stdio.h>
int main() 
{
    char str[200];
    int i;
    scanf("%s", str);
    scanf("%d", &i);
    printf("%s %d\n", str, i);
}