Answers for "passing FILE as argument in c"

C
0

passing FILE as argument in c

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

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;
}
Posted by: Guest on August-30-2021

Code answers related to "passing FILE as argument in c"

Code answers related to "C"

Browse Popular Code Answers by Language