📌  相关文章
📜  将 FILE 作为参数传递 - C 编程语言代码示例

📅  最后修改于: 2022-03-11 15:04:38.555000             🧑  作者: Mango

代码示例1
#include 
#include 
#include 
#include 

void my_write(FILE *fp, char *str)
{
    fprintf(fp, "%s", str);
}

int main(void)
{
    char *str = "test text\n";
    FILE *fp;

    fp = fopen("test.txt", "a");
    if (fp == NULL)
    {
        printf("Couldn't open file\n");
        return 1;
    }
    my_write(fp, str);

    fclose(fp);

    return 0;
}