Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

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
";
    FILE *fp;

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

    fclose(fp);

    return 0;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #passing #FILE #argument
ADD COMMENT
Topic
Name
2+8 =