Q:

C Program to write a variable in a file using the fwrite

belongs to collection: File handling in C

0

C Program to write a variable in a file using the fwrite

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Below code writes the value of integer variable data into the file.

#include <stdio.h>
int main()
{
    //Variable which want to write
    int data  = 65;
    //file pointer
    FILE *fp = NULL;
    //create and open the text file
    fp = fopen("aticleworld.dat", "wb");
    if(fp == NULL)
    {
        printf("Error in creating the file\n");
        exit(1);
    }
    //write the variable in file
    fwrite(&data, sizeof(data), 1, fp);
    fclose(fp);
    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to write an array in a file using the fw... >>
<< C Program to write the message and the length usin...