Question

2. The binary file dates.bin is shown in a hexadecimal editor: DXV132 - dates.bin File Edit earch Address Bookmarks Tools VIscript Help 7000000303530|353134 30333233 31 33 0 5 0 5 1 4 0 323 1 3 ▲ 10 30 31 32 35 31 34 30 38 31 36 31 32 30 37 33 3101 2 5 1 4 0 8 1 6 1 20731 20 31 34 30 32 30 36 31 32 31 31 32 33 31 35 30 39 1 4 0 2 0 61 2 11 2 3 1509 30 31 34 31 33 1 4 1 3 Delete Adr. hex: 0 Char dec: 7 Overwrite The file is full of dates. It starts with an integer (4 bytes) giving the number of dates. The dates are formatted as MMDDYY (two chars for the month, two chars for the day, and two chars for the year). Write a program that reads in this file (or any similarly formatted version of it) and stores all dates from 2014 into a new file called newdates.bin. The new file is a binary file with the same format as dates.bin .

Is any one can help me to write the code? Please.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

struct is analogous to a class. there are differences but you can ignore for now.

here we have created a struct named date which has 3 arrays namely m,d,y each of size 2 and typr char.

we can create object of struct date.eg

strcut date todaysdate;

the arrays can be accessed as follows

todaysdate.m[0]

. FILE pointer to create and use FILE for different operations.

syntax

FILE* filePointerName;

eg.File*infile

fopen()

syntax

fopen(“fileName”,”mode”);

eg.

file*infile=fopen("dates.bin",rb)

rb=readmode for non text files

wb=write mode for non text files

fread()

It is used to read data from file.

syntax of the function is:

fread (void* ptr, t size, t count,FILE* stream)

Parameters

ptr: pointer to memory where the read data will be stored.
size: size of data elements (in byte) to be read.
count: number of data elements to be read.
stream: pointer to the file from which the data will be read.

Return

Type: t
Value: On success number of elements which are successfully read.
On failure returns zero (0) if the size or count is 0, Error indicator is set.

eg.in our case

fread returns the first integer and since as stated the first integer=number of dates in infile hence datecount.

then we create arrays namely dates and keeperdate both of size datecount

fread(dates,sizeof(struct date),datecount,infile)

reads all dates and stores it in array dates as objects of struct date

Note: fread skips those characters which do not obey the size specified , so second call to fread does not reads the datecount which is the first integer in your file.

the for loop.

iterates through dates array and

It checks if the year of date ==14 [since we have to only copy dates of 2014]

if(yes)

save that date in Keeper array and increment keepercount

fwrite().

It is used for file writing.

syntax is:

fwrite(const void* ptr, t size,t count,FILE* stream)

Parameters:

ptr: pointer to the data which will be written.
size: the size of data elements (in byte) to be written.
count: number of data elements to be written.
stream: the pointer to the file where the data will be written.

Return

Type: t
Value: On success number of elements which are successfully written
On failure zero (0) if the size or count is 0. Error indicator is set.

fwrite(&keppercount,sizeof(int)1,outfile);

it simply outputs datecount as first integer of file

fwrite(keeperdates,sizeof(struct date),keepcount,outfile)

outputs all date objects in keeperdates array into outfile.

return 0; to exit

Note: fwrite appends to end of file.

Add a comment
Know the answer?
Add Answer to:
Is any one can help me to write the code? Please. 2. The binary file dates.bin...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please show work! 2. Now, give it a try by converting the binary number 01110110 to...

    Please show work! 2. Now, give it a try by converting the binary number 01110110 to decimal by filling in the same table in step 1 r of 2 Pov 128 64 32 16 Cumulative Amount 4. Now, you give it a try by converting the decimal number 131 to binary by filling in the table Power of 2 128 32 16 Bit Amount Remaining 6. Use the binary to hexadecimal table to convert the binary number 01101111 to hexadecimal...

  • These are my instructions: Your data should have been read in from the data file and stored into ...

    These are my instructions: Your data should have been read in from the data file and stored into an array. Next you need to calculate the following and display in a single Message box: Average score Highest score Lowest score Mode of the scores Your program should be written using methods and should be well documented internally and externally. Your output should be displayed using Message boxes. This is the .text file to use with the instructions: 20 21 22...

  • mips add matrix Can anyone help me with adding matrix in MIPS? This is the code...

    mips add matrix Can anyone help me with adding matrix in MIPS? This is the code given. We will be using it to run it in spim-cache Write an assembly code program to perform addition between two matrices A and B, and store the result into a matrix C, i.e, 1 2 3 4 51 [26 27 28 29 301 27 29 31 33 35 6 7 8 9 10 31 32 33 34 35 37 39 41 43 45...

  • Write a VERILOG simulation code for a 3 to 8 decoder and a simulation code for...

    Write a VERILOG simulation code for a 3 to 8 decoder and a simulation code for a 4 to 16 decoder using two 3 to 8 decoders. The code used for 3 to 8 decoder: Code used for 4 to 16 decoder: Need help with simulation code. 22 module Dec3to8 ( 23 input [2:0 A input E output [7:0] D 24 25 26 27 E &A[2]& 28 assign D[0] A[1 A[0] E &A[2] &A[1] assign D[1] & A[0] 29 E...

  • Arrays: City temperatures The maximum daily temperatures (in "C) for Istanbul and Ankara during August 2019...

    Arrays: City temperatures The maximum daily temperatures (in "C) for Istanbul and Ankara during August 2019 are given below. Ankara: [33 30 31 32 33 35 30 29 29 28 29 30 32 32 33 32 34 31 33 30 29 30 31 33 31 30 27 26 27 26 27] Istanbul: [35 32 32 31 34 30 29 32 34 35 36 35 34 32 33 33 34 35 35 34 32 30 30 29 28 31 32 30...

  • (use filename system: lastname_tempdata_firstinitial.m) 1. Gilat Chapter 6 Chapter7 #6. Use a single M-file and use...

    (use filename system: lastname_tempdata_firstinitial.m) 1. Gilat Chapter 6 Chapter7 #6. Use a single M-file and use mnemonic variable names of 3 characters or more for the variables to complete the problem. This is a comparison problem. If, selection, statements are not required but may be used. Loops are not required but may be used. Do not add any user defined M-files for this problem. Use fprintf statements to show the answer to each scenario: a), b), c), d), e) Investigate...

  • 26. Nazsai Soolen sullebe Exercise 1 Naming Simple Binary Compounds Name each of the following simple...

    26. Nazsai Soolen sullebe Exercise 1 Naming Simple Binary Compounds Name each of the following simple binary compounds. 1. H30 2. LO 3. sro 4. Al:O 5. NaCl 6. Mgs e o se 8. KPL 9. RbCl 10. Sr.P 11. HIS 27. KI 28. Cao 29. Bel2 30. AICI: 31. AIP 32. LiBr 33. Rb3N 34. RDF 35. AIP 36. All 37. HBr 38. Mgo 39. Bes 40. MON 41. Sr3N2 42. Cas 43. BesP2 12. BO CH 15. Bech...

  • Age Formulas 30 Sample size 47 38 27 Sample mean (2 decimals) 31.51 =AVERAGE(A:A) 35...

    Age Formulas 30 Sample size 47 38 27 Sample mean (2 decimals) 31.51 =AVERAGE(A:A) 35 26 Sample Standard Deviation (4 decimals) 4.1852 =STDEV.S(A:A) 36 29 Hypothesized Mean 32 34 33 Test Statistic (3 decimals) -0.802 =(D4-D8)/(D6/SQRT(D2)) 33 29 Degrees of Freedom 46 =D2-1 31 40 p-value (3 decimals) need this need this 25 35 Level of Significance (Alpha) 0.05 32 27 Reject Null Hypothesis? #N/A 31 36 34 34 32 31 31 32 30 39 25 29 31 37 37...

  • please answer it correctly because this is my last attempt thankyou! Consider the hypothesis test Ho...

    please answer it correctly because this is my last attempt thankyou! Consider the hypothesis test Ho : H1 – uz = 0 against H1 : Hi – M2 0 samples below: I 36 39 32 33 33 30 32 29 39 38 31 37 37 30 39 32 35 38 II 3330 34 33 32 29 30 36 32 34 30 30 31 33 33 34 Variances: j = 3.8, 02 = 2.4. Use a = 0.05. (a) Test the...

  • Suppose a binary tree data (in tiny written size) is stored in an array (A) as...

    Suppose a binary tree data (in tiny written size) is stored in an array (A) as given below and root is placed at “0”index. Note the array indices are in larger written size (0 to 74). Show the traversal data of the given tree for a)      In-Order Traversal b)     Post Order Traversal A 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 3 28 13 36 15 9 22 44 7 10 75 33 19 15...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT