<div class="text-justify"> ##### <center>Hello Everyone</center> <center> </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></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></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></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></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></center> <center></center> </div> <h3>Stay Home, Stay Safe</h3> #### <center>*@peerzadazeeshan*</center> </center></p></div> </div> </div>
author | peerzadazeeshan | ||||||
---|---|---|---|---|---|---|---|
permlink | programming-in-c-binary-file-i-o-funtions | ||||||
category | hive-175254 | ||||||
json_metadata | {"app":"peakd/2020.04.5","format":"markdown","tags":["programming","education","edu-venezuela","upfundme","hive","posh"],"users":["peerzadazeeshan","zord189"],"links":["https://images.app.goo.gl/6XzumkqqxC8QqusU7","/hive-122108/@peerzadazeeshan/c-programing-file-processing","/hive-196387/@peerzadazeeshan/programming-in-c-file-operations","/hive-122108/@peerzadazeeshan/programming-in-c-text-file-input-output-i-o","/@zord189","/@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"]} | ||||||
created | 2020-04-30 15:20:33 | ||||||
last_update | 2020-04-30 15:25:06 | ||||||
depth | 0 | ||||||
children | 6 | ||||||
last_payout | 2020-05-07 15:20:33 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 7.186 HBD | ||||||
curator_payout_value | 8.968 HBD | ||||||
pending_payout_value | 0.000 HBD | ||||||
promoted | 0.000 HBD | ||||||
body_length | 5,652 | ||||||
author_reputation | 20,072,110,145,141 | ||||||
root_title | "Programming in C—Binary File I/O Funtions." | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||
percent_hbd | 10,000 | ||||||
post_id | 97,098,206 | ||||||
net_rshares | 24,342,803,165,504 | ||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
bitshares101 | 0 | 109,819,184,997 | 25% | ||
vortac | 0 | 747,128,328,794 | 15% | ||
xpilar | 0 | 2,265,167,529,349 | 70% | ||
thedrollyears | 0 | 10,129,691,902 | 100% | ||
chesatochi | 0 | 242,051,494,936 | 50% | ||
gbenga | 0 | 7,621,918,497 | 53% | ||
khussan | 0 | 914,045,174 | 70% | ||
jagged | 0 | 78,239,472,595 | 25% | ||
samminator | 0 | 82,683,331,437 | 70% | ||
pibyk | 0 | 7,142,189,183 | 100% | ||
btcsam | 0 | 24,298,636,974 | 100% | ||
vikisecrets | 0 | 343,817,239,962 | 30% | ||
syedumair | 0 | 39,841,074,797 | 10% | ||
tipu | 0 | 2,025,364,449,417 | 5% | ||
bboyady | 0 | 7,918,701,522 | 25% | ||
vlemon | 0 | 247,673,108,239 | 20% | ||
davidke20 | 0 | 113,364,821,242 | 50% | ||
carrieallen | 0 | 20,218,882,576 | 30% | ||
vishalsingh4997 | 0 | 2,906,334,479 | 50% | ||
josediccus | 0 | 20,305,127,653 | 5% | ||
mikitaly | 0 | 26,028,871,161 | 100% | ||
lemon-shot | 0 | 856,593,994 | 5% | ||
fortunex | 0 | 12,291,798,180 | 50% | ||
bartheek | 0 | 1,011,389,456 | 2.5% | ||
gandhibaba | 0 | 36,352,296,957 | 10% | ||
lanzjoseg | 0 | 141,560,302,872 | 100% | ||
felixgarciap | 0 | 2,843,839,188 | 10.6% | ||
happy-soul | 0 | 17,479,270,122 | 2.5% | ||
yurilaya | 0 | 1,045,792,759 | 50% | ||
zoniacb | 0 | 1,299,541,075 | 100% | ||
retinox | 0 | 61,847,728,652 | 34.46% | ||
josevas217 | 0 | 53,641,281,744 | 85% | ||
phbr | 0 | 4,780,954,618 | 50% | ||
paragism | 0 | 894,954,944 | 7.95% | ||
rzs | 0 | 6,080,593,795 | 25% | ||
cyemela | 0 | 591,209,365 | 26.5% | ||
ritxi | 0 | 69,712,072,485 | 50% | ||
crypto.piotr | 0 | 289,635,819,285 | 70% | ||
cryptomaniacsgr | 0 | 35,428,774,120 | 100% | ||
minerthreat | 0 | 971,688,036 | 26.5% | ||
truthtrader | 0 | 10,549,683,077 | 50% | ||
tysler | 0 | 100,831,316,070 | 95% | ||
achim03 | 0 | 17,612,699,865 | 70% | ||
karamyog | 0 | 21,137,337,790 | 100% | ||
nutritree | 0 | 8,657,838,852 | 35% | ||
bigpower | 0 | 224,695,359,280 | 70% | ||
cyberspacegod | 0 | 832,650,389 | 53% | ||
erica005 | 0 | 791,983,867 | 13.25% | ||
deathcross | 0 | 70,254,109,340 | 100% | ||
kryptarion | 0 | 2,719,458,708 | 49% | ||
steemitcentral | 0 | 193,016,997,011 | 70% | ||
alokkumar121 | 0 | 4,631,812,494 | 5% | ||
sasaadrian | 0 | 1,879,697,040 | 20% | ||
reverseacid | 0 | 10,762,887,358 | 70% | ||
conectionbot | 0 | 4,094,621,043 | 100% | ||
cwow2 | 0 | 204,310,319,690 | 70% | ||
reflektor | 0 | 4,652,365,177,783 | 70% | ||
steemegg | 0 | 4,009,004,970 | 12.5% | ||
bippe | 0 | 1,719,203,240,334 | 70% | ||
junnel123 | 0 | 706,002,099 | 35% | ||
hingsten | 0 | 1,894,099,415,660 | 70% | ||
help.venezuela | 0 | 160,477,514,346 | 70% | ||
cryptogambit | 0 | 1,442,707,357 | 7.5% | ||
worldhelper | 0 | 20,023,046,068 | 70% | ||
tomlee | 0 | 6,515,790,470 | 26.5% | ||
lrcconsult | 0 | 72,136,280,043 | 70% | ||
project.hope | 0 | 7,649,831,035,293 | 53% | ||
dappstats | 0 | 4,869,037,586 | 15% | ||
javb | 0 | 1,688,317,538 | 100% | ||
ph-fund | 0 | 75,124,005,667 | 100% | ||
hope.venezuela | 0 | 552,463,515 | 100% | ||
awah | 0 | 14,610,024,659 | 58% | ||
brage | 0 | 23,218,584,980 | 70% | ||
hive-180870 | 0 | 785,914,323 | 20% | ||
teach-me | 0 | 1,183,119,772 | 49% | ||
sunsan | 0 | 2,223,374,634 | 26.5% |
@tipu curate
author | crypto.piotr |
---|---|
permlink | q9pfe2 |
category | hive-175254 |
json_metadata | {"users":["tipu"],"app":"hiveblog/0.1"} |
created | 2020-05-02 12:43:42 |
last_update | 2020-05-02 12:43:42 |
depth | 1 |
children | 1 |
last_payout | 2020-05-09 12:43:42 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 12 |
author_reputation | 27,396,789,428,606 |
root_title | "Programming in C—Binary File I/O Funtions." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 97,138,116 |
net_rshares | 0 |
<a href="https://tipu.online/hive_curator?crypto.piotr" target="_blank">Upvoted 👌</a> (Mana: 24/30)
author | tipu |
---|---|
permlink | re-q9pfe2-20200502t124357 |
category | hive-175254 |
json_metadata | "" |
created | 2020-05-02 12:43:57 |
last_update | 2020-05-02 12:43:57 |
depth | 2 |
children | 0 |
last_payout | 2020-05-09 12:43:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 108 |
author_reputation | 55,938,768,526,111 |
root_title | "Programming in C—Binary File I/O Funtions." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 97,138,122 |
net_rshares | 0 |
I suggest you learn how to embed code properly in your article. the best way to do is to use the three back tick syntax like this:  Adding the programming language might activate syntax highlight. Not on Steem/Hive right now but it might come later. The result looks like this. ```ruby if Accounts.length == 0 then puts "No accounts found.".yellow else pp Accounts end ```
author | krischik |
---|---|
permlink | re-peerzadazeeshan-q9lyja |
category | hive-175254 |
json_metadata | {"tags":["hive-175254"],"app":"peakd/2020.04.5"} |
created | 2020-04-30 15:47:36 |
last_update | 2020-04-30 15:47:36 |
depth | 1 |
children | 1 |
last_payout | 2020-05-07 15:47:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 479 |
author_reputation | 15,247,708,436,415 |
root_title | "Programming in C—Binary File I/O Funtions." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 97,098,630 |
net_rshares | 0 |
Thanks for the suggestion, I will do it in my next post.
author | peerzadazeeshan |
---|---|
permlink | re-krischik-q9m0bb |
category | hive-175254 |
json_metadata | {"tags":["hive-175254"],"app":"peakd/2020.04.5"} |
created | 2020-04-30 16:26:00 |
last_update | 2020-04-30 16:26:00 |
depth | 2 |
children | 0 |
last_payout | 2020-05-07 16:26:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 56 |
author_reputation | 20,072,110,145,141 |
root_title | "Programming in C—Binary File I/O Funtions." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 97,099,210 |
net_rshares | 0 |
I'm resteeming this post. Hopefully it will get some more exposure and engagement. Yours, Piotr
author | project.hope |
---|---|
permlink | q9m142 |
category | hive-175254 |
json_metadata | {"app":"hiveblog/0.1"} |
created | 2020-04-30 16:42:33 |
last_update | 2020-04-30 16:42:33 |
depth | 1 |
children | 1 |
last_payout | 2020-05-07 16:42:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 96 |
author_reputation | 3,880,876,099,761 |
root_title | "Programming in C—Binary File I/O Funtions." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 97,099,596 |
net_rshares | 0 |
Thank you for helping out.
author | peerzadazeeshan |
---|---|
permlink | q9m173 |
category | hive-175254 |
json_metadata | {"app":"hiveblog/0.1"} |
created | 2020-04-30 16:45:06 |
last_update | 2020-04-30 16:45:06 |
depth | 2 |
children | 0 |
last_payout | 2020-05-07 16:45:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 26 |
author_reputation | 20,072,110,145,141 |
root_title | "Programming in C—Binary File I/O Funtions." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 97,099,629 |
net_rshares | 0 |