<div class="text-justify"> ##### <center>Hello Everyone</center> <center> ![images.jpeg](https://files.peakd.com/file/peakd-hive/peerzadazeeshan/Q84ngyN8-images.jpeg)</center> <center><sup>[Image Source](https://images.app.goo.gl/6XzumkqqxC8QqusU7)</sup></center> I hope you all are fine and safe inside your homes. This is a weird time ongoing in the whole world and I hope it will get over soon. As during this time, everyone is locked into their homes. I want to share C programming language with you. I hope you guys like it, so lets happen today's topic. #### <center> Binary File Input Output (I/O) Functions</center> Have you ever thought, how can a large amount of numerical data be stored in file? Is it sufficient to store in text mode? Well, a large amount of numerical data can not be stored in text mode. In such a case **Binary File** is used. Working on binary files is identical to text file with rare discrepancies in the opening, reading and writing to file. Opening modes of binary files are **rb+, rb, wb+, wb, ab+** and **ab**. Only differences between opening modes of binary files and text files is that **b** is appended to indicate it is a ***Binary File**. ###### *fread() and fwrite()*— Functions for reading and writing Binary File. These two functions *fread()* and *fwrite()* are used for reading from and writing to a file on disk respective of binary files. ***fwrite()*** Functions *fwrite()* takes 4 arguments. Address, size of data should be written in disk, number of type of data and pointer to file where user wants to write. **Syntax:** <code>fwrite(address_data,size_data,numbers_data,pointer_to_file);</code> **Example:** <code>#include <stdio.h> struct marks { int m1, m2,m3,m4,m5; }; void main() { int n; struct marks m; FILE *fptr; if ((fptr = fopen("C:\\TURBOC3\\mark.bin","wb")) == NULL){ printf("File Cannot Open!"); exit(1); } printf("Enter 5 Students Marks\n"); for(n = 1; n <= 5; ++n) { printf("Enter English Mark of Student %d : ", n); scanf("%d",&m.m1); printf("Enter Math's Mark of Student %d : ", n); scanf("%d",&m.m2); printf("Enter Physics Mark of Student %d : ", n); scanf("%d",&m.m3); printf("Enter Chemistry Mark of Student %d : ", n); scanf("%d",&m.m4); printf("Enter Python Mark of Student %d : ", n); scanf("%d",&m.m5); fwrite(&m, sizeof(struct marks), 1, fptr); } fclose(fptr); }</code> ###### Output of above program: <center>![IMG_20200430_190828.jpg](https://files.peakd.com/file/peakd-hive/peerzadazeeshan/1uB5yp9s-IMG_20200430_190828.jpg)</center> <center><sup>Output got after execution of program</sup></center> In the above program, user can create a new file **mark.bin** in ***C:\\TURBOC3\\*** path. Structure of the marks with 5 integers are declared as m1,m2,m3,m4 and m5 and are defined it in new function **m** as main function. User can read 5 subject marks and can store value into the file with the help of **fwrite()** function. Address of the **m** is stored in first parameter and second parameter takes size of marks structured. Since, only one instance of **m** is to be inserted so third parameter is 1. ***fptr** points to the file where data is to be stored. On last step, file is closed. ***fread()*** The function **fread()** also takes the same 4 arguments which **fwrite()** takes. **Syntax:** <code>fread(address_data,size_data,numbers_data,pointer_to_file);</code> **Example:** <code>#include <stdio.h> struct marks { int m1, m2,m3,m4,m5; }; void main() { int n; struct marks m; FILE *fptr; if ((fptr = fopen("C:\\TURBOC3\\mark.bin","rb")) == NULL){ printf("Cannot Open File !"); exit(1); } printf("Marks are\n"); for(n = 1; n <= 5; ++n) { fread(&m, sizeof(struct marks), 1, fptr); printf("Student %d Marks : English: %d\t Maths : %d\t Physics: %d\t Chemistry : %d\t Python: %d\n",n, m.m1, m.m2, m.m3,m.m4,m.m5); } fclose(fptr); }</code> ###### Output of the above program: <center>![IMG_20200430_203542.jpg](https://files.peakd.com/file/peakd-hive/peerzadazeeshan/RwkwHngd-IMG_20200430_203542.jpg)</center> <center><sup>Output got after execution of above program</sup></center> In the above program, user can read the same file **mark.bin** in ***C:\\TURBOC3\\*** path and loop through records respectively one by one. Simply, one marks record of marks size is read from the file indicated **fptr* into structure **m**. By doing all this procedure, user will get the same records which inserted in previous Example. <center>![Logo.png](https://files.peakd.com/file/peakd-hive/peerzadazeeshan/i01yOun5-Logo.png)</center> ##### My last posts on programming, if you want to read go through it. <center> 1: [Ist post—File processing](https://hive.blog/hive-122108/@peerzadazeeshan/c-programing-file-processing). 2: [2nd post—File Operations](https://hive.blog/hive-196387/@peerzadazeeshan/programming-in-c-file-operations) 3: [3rd post—Text File I/O](https://hive.blog/hive-122108/@peerzadazeeshan/programming-in-c-text-file-input-output-i-o) </center> <center>![Logo.png](https://files.peakd.com/file/peakd-hive/peerzadazeeshan/i01yOun5-Logo.png)</center> ##### <center>Thank you. #### I hope you guys liked my post. #### Keep Supporting. #### *STAY TUNED FOR NEXT POST* <center> |UPVOTE|COMMENT|RESTEEM| |-|-|-| |IF YOU|LIKED|MY POST| </center> </center> <center>![Logo.png](https://files.peakd.com/file/peakd-hive/peerzadazeeshan/i01yOun5-Logo.png)</center> <center>![Created by @zord189](https://files.peakd.com/file/peakd-hive/peerzadazeeshan/UzLYooQj-peerzadazeeshan.gif)</center> </div> <h3>Stay Home, Stay Safe</h3> #### <center>*@peerzadazeeshan*</center> </center></p></div> </div> </div>
post_id | 86,022,522 | ||||||
---|---|---|---|---|---|---|---|
author | peerzadazeeshan | ||||||
permlink | programming-in-c-binary-i-o-functions | ||||||
category | hive-175254 | ||||||
json_metadata | {"tags":["hive-175254","steemit","education","programming","technology"],"users":["peerzadazeeshan"],"image":["https:\/\/files.peakd.com\/file\/peakd-hive\/peerzadazeeshan\/Q84ngyN8-images.jpeg","https:\/\/files.peakd.com\/file\/peakd-hive\/peerzadazeeshan\/1uB5yp9s-IMG_20200430_190828.jpg","https:\/\/files.peakd.com\/file\/peakd-hive\/peerzadazeeshan\/RwkwHngd-IMG_20200430_203542.jpg","https:\/\/files.peakd.com\/file\/peakd-hive\/peerzadazeeshan\/i01yOun5-Logo.png","https:\/\/files.peakd.com\/file\/peakd-hive\/peerzadazeeshan\/UzLYooQj-peerzadazeeshan.gif"],"links":["https:\/\/images.app.goo.gl\/6XzumkqqxC8QqusU7","https:\/\/hive.blog\/hive-122108\/@peerzadazeeshan\/c-programing-file-processing","https:\/\/hive.blog\/hive-196387\/@peerzadazeeshan\/programming-in-c-file-operations","https:\/\/hive.blog\/hive-122108\/@peerzadazeeshan\/programming-in-c-text-file-input-output-i-o"],"app":"steemit\/0.2","format":"markdown"} | ||||||
created | 2020-05-16 10:06:00 | ||||||
last_update | 2020-05-16 10:06:00 | ||||||
depth | 0 | ||||||
children | 6 | ||||||
net_rshares | 10,498,049,271,126 | ||||||
last_payout | 2020-05-23 10:06:00 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 1.938 SBD | ||||||
curator_payout_value | 2.410 SBD | ||||||
pending_payout_value | 0.000 SBD | ||||||
promoted | 0.000 SBD | ||||||
body_length | 5,652 | ||||||
author_reputation | 12,816,746,004,355 | ||||||
root_title | "Programming in C—Binary I/O Functions." | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 SBD | ||||||
percent_steem_dollars | 0 | ||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
followforupvotes | 0 | 7,307,561,793 | 20% | ||
red-rose | 0 | 5,615,014,728 | 60% | ||
mtl1979 | 0 | 0 | 100% | ||
syedubair | 0 | 43,148,388,822 | 100% | ||
guruvaj | 0 | 849,801,822 | 25.5% | ||
adityajainxds | 0 | 3,739,465,357 | 20% | ||
soufiani | 0 | 642,005,508 | 0.8% | ||
retinox | 0 | 28,605,491,353 | 25.73% | ||
scottshots | 0 | 618,509,735 | 4% | ||
crypto.piotr | 0 | 505,271,583,033 | 54% | ||
zainenn | 0 | 12,889,904,996 | 10% | ||
deathcross | 0 | 138,246,562,249 | 100% | ||
dcooperation | 0 | 2,582,326,244 | 1% | ||
reverseacid | 0 | 8,460,488,759 | 54% | ||
edgarare1 | 0 | 59,862,701,564 | 20% | ||
project.hope | 0 | 2,538,358,981,497 | 30% | ||
steemcab | 0 | 937,079,336 | 100% | ||
pramge | 0 | 0 | -10% | ||
block.token | 0 | 3,981,283,196 | 100% | ||
steemcurator06 | 0 | 7,136,932,121,134 | 100% |
As a follower of @followforupvotes this post has been randomly selected and upvoted! Enjoy your upvote and have a great day!</sup></center>
post_id | 86,022,558 |
---|---|
author | followforupvotes |
permlink | re-peerzadazeeshan-programming-in-c-binary-i-o-functions-20200516t101100125z |
category | hive-175254 |
json_metadata | {} |
created | 2020-05-16 10:11:03 |
last_update | 2020-05-16 10:11:03 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2020-05-23 10:11:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 139 |
author_reputation | 24,990,662,983,063 |
root_title | "Programming in C—Binary I/O Functions." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
@peerzadazeeshan currently c language is used everywhere as it is master of all language. before i also tried to learn but cannot get it.
post_id | 86,024,552 |
---|---|
author | adityajainxds |
permlink | qafhbo |
category | hive-175254 |
json_metadata | {"users":["peerzadazeeshan"],"app":"steemit\/0.2"} |
created | 2020-05-16 14:23:39 |
last_update | 2020-05-16 14:23:39 |
depth | 1 |
children | 2 |
net_rshares | 0 |
last_payout | 2020-05-23 14:23:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 137 |
author_reputation | 221,026,549,797,064 |
root_title | "Programming in C—Binary I/O Functions." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Few years ago it was considered as master of all languages but from past 3-4 years Java was considered as master language. Thanks to corona, it is used everywhere nowadays for researching and now it surpassed Java too...
post_id | 86,030,841 |
---|---|
author | peerzadazeeshan |
permlink | qagkmc |
category | hive-175254 |
json_metadata | {"app":"steemit\/0.2"} |
created | 2020-05-17 04:32:39 |
last_update | 2020-05-17 04:33:03 |
depth | 2 |
children | 1 |
net_rshares | 0 |
last_payout | 2020-05-24 04:32:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 222 |
author_reputation | 12,816,746,004,355 |
root_title | "Programming in C—Binary I/O Functions." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Java is pretty much ancient history, but instead JavaScript is used extensively by web-enabled applications... A lot of programs recently have been written in Python.
post_id | 86,116,985 |
---|---|
author | mtl1979 |
permlink | re-peerzadazeeshan-qaubn2 |
category | hive-175254 |
json_metadata | {"tags":["hive-175254"],"app":"steempeak\/2020.05.1"} |
created | 2020-05-24 14:45:06 |
last_update | 2020-05-24 14:45:06 |
depth | 3 |
children | 0 |
net_rshares | 0 |
last_payout | 2020-05-31 14:45:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 166 |
author_reputation | 702,532,898,973 |
root_title | "Programming in C—Binary I/O Functions." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
This post has been rewarded by the Steem Community Curation Project. #communitycuration06.
post_id | 86,068,169 |
---|---|
author | steemcurator06 |
permlink | qam7ns |
category | hive-175254 |
json_metadata | {"tags":["communitycuration06"],"app":"steemit\/0.2"} |
created | 2020-05-20 05:05:21 |
last_update | 2020-05-20 05:05:21 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2020-05-27 05:05:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 90 |
author_reputation | 992,354,096,132 |
root_title | "Programming in C—Binary I/O Functions." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Assignment inside if condition might confuse people still new to programming.
post_id | 86,117,096 |
---|---|
author | mtl1979 |
permlink | re-peerzadazeeshan-qaubzu |
category | hive-175254 |
json_metadata | {"tags":["hive-175254"],"app":"steempeak\/2020.05.1"} |
created | 2020-05-24 14:52:51 |
last_update | 2020-05-24 14:52:51 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2020-05-31 14:52:51 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 77 |
author_reputation | 702,532,898,973 |
root_title | "Programming in C—Binary I/O Functions." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |