Q:

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

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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now