Answers for "write arguments into file 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 textn";
    FILE *fp;

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

    fclose(fp);

    return 0;
}
Posted by: Guest on August-30-2021

Code answers related to "C"

Browse Popular Code Answers by Language