![]() |
The structure in C allows the users to create user-defined data types that can be used to group data items of different types into a single unit. We can save this structure in a file using C file handling. In this article, we will learn how we can read a struct from a binary file in C. Read a Struct from a Binary File in CTo read a struct from a binary file in C, we will first have to open the binary file using the fopen() method in rb mode. Then we will use the fread() function to read the structure from the file. Syntax of fread()size_t fread(void * buffer, size_t size, size_t count, FILE * stream);
here,
C Program to Read a Struct from a Binary FileC
Output Employee ID: 1, Name: John Doe, Salary: 50000.0 Time Complexity: O(N) where N is the number of structs in the file |
Reffered: https://www.geeksforgeeks.org
C Language |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |