c语言中作为不同文件描述符的多个流
我有一个程序,我需要提供2个不同的流作为输入 如果我只需要一个流作为输入,我可以像这样使用stdinc语言中作为不同文件描述符的多个流,c,file-descriptor,C,File Descriptor,我有一个程序,我需要提供2个不同的流作为输入 如果我只需要一个流作为输入,我可以像这样使用stdin ./a.out <file1 fgets(buf,1000,stdin) /a.out如果使用bash作为shell,可以执行以下操作: ./a.out 3< file1 4< file2 /a.out 3
./a.out <file1
fgets(buf,1000,stdin)
/a.out如果使用bash作为shell,可以执行以下操作:
./a.out 3< file1 4< file2
/a.out 3
如果使用bash作为shell,可以执行以下操作:
./a.out 3< file1 4< file2
/a.out 3
您可以这样运行程序:
./a.out file1 file2
int main(int argc, char *argv[]) {
FILE *fp1 = fopen(argv[1], "r");
FILE *fp2 = fopen(argv[2], "r");
fgets(buf1, length_of_buf1, fp1);
fgets(buf2, length_of_buf2, fp2);
并在程序中使用这些文件,如下所示:
./a.out file1 file2
int main(int argc, char *argv[]) {
FILE *fp1 = fopen(argv[1], "r");
FILE *fp2 = fopen(argv[2], "r");
fgets(buf1, length_of_buf1, fp1);
fgets(buf2, length_of_buf2, fp2);
您可以这样运行程序:
./a.out file1 file2
int main(int argc, char *argv[]) {
FILE *fp1 = fopen(argv[1], "r");
FILE *fp2 = fopen(argv[2], "r");
fgets(buf1, length_of_buf1, fp1);
fgets(buf2, length_of_buf2, fp2);
并在程序中使用这些文件,如下所示:
./a.out file1 file2
int main(int argc, char *argv[]) {
FILE *fp1 = fopen(argv[1], "r");
FILE *fp2 = fopen(argv[2], "r");
fgets(buf1, length_of_buf1, fp1);
fgets(buf2, length_of_buf2, fp2);
您可以为此使用命名管道。或临时文件。您可以为此使用命名管道。或临时文件。