小编sau*_*abh的帖子

如何恢复标准输出的文件描述符?

我需要帮助来理解文件描述符

所以这是我的代码:

int main()
{
    char ch;
    close(1);
    //now opening a file so that it gets the lowest possible fd i.e. 1
    int fd=open("txt",O_RDWR);
    //check..
    printf("first printtf is executed\n");
    scanf("%c",&ch);
    printf("ur value is %c\n",ch);

    printf("second printf is executed\n");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在上面的程序中,我尝试将 的输出重定向printftxt文件而不是标准输出,即终端。但是如何恢复标准输出文件描述符,以便printf在第二种情况下再次正常工作,即第二个printtf应该只向终端提供输出..

c linux printf file-descriptor system-calls

0
推荐指数
1
解决办法
2032
查看次数

标签 统计

c ×1

file-descriptor ×1

linux ×1

printf ×1

system-calls ×1