inptr和outptr是什么意思

What does inptr and outptr mean

有谁知道inptr和outptr是什么意思?我知道它是 in 和 out 指针的缩写,但我似乎无法理解它的用途?另外,如果你能告诉我为什么 FILE 在那里也很合适。 谢谢!

char *infile = argv[1]; char *outfile = argv[2];

// open input file
FILE *inptr = fopen(infile, "r");
if (inptr == NULL)
{
    printf("Could not open %s.\n", infile);
    return 2;
}

// open output file
FILE *outptr = fopen(outfile, "w");
if (outptr == NULL)
{
    fclose(inptr);
    printf("Could not create %s.\n", outfile);
    return 3;
}

inptr 对应于您的程序正在读取的文件,outptr 对应于您的程序正在写入的文件。

大多数 C I/O 函数采用指向 FILE 类型的指针,它封装了 I/O 通道(称为 stream) 为您的系统(FILE 类型的确切结构因系统而异,这些细节对您是隐藏的)。 inptroutptr 分别映射到您的输入和输出文件。