belongs to collection: File handling in C
Writing a structure in a file using the fwrite in C
The below code writes the id, first name and last name of the employee using the fwrite into the file.
#include <stdio.h> typedef struct { int id; char fName[16]; char lName[16]; } s_employee; int main() { //Populate structure variable s_employee sAmlendraInfor = {8886, "Amlendra", "Mishra"}; //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 structure in file fwrite(&sAmlendraInfor, sizeof(sAmlendraInfor),1, fp); fclose(fp); return 0; }
Output:
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
The below code writes the id, first name and last name of the employee using the fwrite into the file.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer