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:
![](data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAMDAwMDAwQEBAQFBQUFBQcHBgYHBwsICQgJCAsRCwwLCwwLEQ8SDw4PEg8bFRMTFRsfGhkaHyYiIiYwLTA+PlQBAwMDAwMDBAQEBAUFBQUFBwcGBgcHCwgJCAkICxELDAsLDAsRDxIPDg8SDxsVExMVGx8aGRofJiIiJjAtMD4+VP/CABEIAGcCBAMBIgACEQEDEQH/xAAdAAEAAQUBAQEAAAAAAAAAAAAABgECBAUHAwgJ/9oACAEBAAAAAP0V3NtuQAap7+Hovs1O8judsc5rs3S3XZN+Jl5wAYdmJmZwAGB68M6bMMnHzfbFxs7w8vHZ2WtsAAAAAAAIhh8D7lZme+t9MzH3t8fV0uxlG/AAAAAAAERltK1ABRUAAAAAAAIfXNkKJ7FvI9ss6muzfWKb7NUiW3zsoAAAAAAIfrIlJek8s0fp22FQ/wALNJ2rfc253vuy5PDtTf8AQ4AAAAAAQqUqlF6iqqitLK0xcxWoAAAAACJfn99q9f8AP4SkHRdLnxyb6z6WuCkY+I+/+0Hmmq+lrgAAAAAIhEeusSM6C3P2kZm0K6oBrdLHc/YbSD9TAAAAAARKWgFFQFBUAAAAAAIlLQAAAAAAAAABEpaAAAAAAAAAAIlLQAAAAAAAAAB//8QAFw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IEEPAgITJAUWKiE0NQYGOS/9oACAECAQE/AEpctoi4Y4KEKP4BK2LcI2Ii4n0yX7exa3O/mT4wmpIuQE1a7cpO13CW7XQHuUEiwJKr+AmrliN0U064mi1Ackl7waWvdY/xHCVQa2kxbPYSc4ho6EjzU0Skcvzytdyl7spB1TtuZa7frP8A/8QALhEAAQIEAgYLAQAAAAAAAAAAAgASAwQQQgEiEyAyQFCiITFDYGJygpKhwdLw/9oACAEDAQE/AIp6IXKVnwmY0SGIdXAI8LTAwlKSEGUOIYdpwC01irTRf3uqO0hzDmWN6voX73bHphu+PTiX0r03LlTnA4fBzE2jlc3UPFkN3n5UWWlzd0tbW1tLna213Y//2Q==)
need an explanation for this answer? contact us directly to get an explanation for this answer