[Solved] Stage 1: Initialising a C struct and printing it out as text [3 marks] In this stage you will declare a C data structure
Stage 1: Initialising a C struct and printing it out as text [3 marks]
In this stage you will declare a C data structure, create an instance of it and statically initialize it
(declare it as a static or global variable and initialise it in one statement using braces). You will then
print out the instance. This stage develops the following specific skills:
? Declaring a C struct.
? Initialising a C struct
? Printing various data types using printf
Note: Do not use bit fields in your struct. All the data types that are specified correspond to
ordinary C data types.
Note: The automarker checks your struct definition against expected ways of writing it and
awards marks for correctness. Field names must be exactly correct. Types should be the common C
language data types as defined in ANSI C.
Resources
The following documents on iLearn may be helpful:
? Compile, Run, Make C Programs on Linux
? C Programming Notes for Data File Lab
Your downloaded stage1.tar file contains the following files:
? filestruct-description.txt: A simple description of the fields that are in your
struct – their names and type description.
? initialisation-specification.txt: Specifies the initial value for each field of
your struct. The initial value has to be formatted in a specific way in your source code – this
may mean that you have to convert one representation to another. See the lab note
Decimal, Binary, Octal and Hex. Note: It makes no difference to the data that is stored inside
the computer whether you initialise the field with decimal or the equivalent hexadecimal or
octal. However, as an exercise, we require you to make the appropriate type conversions
and the automarker will check your code.
? expected-output.txt: Stage 1 expected output file. Use the example in this file to
work out what formatting options to use in printf.
Useful Unix commands
You might find the following Unix system commands helpful.
? cat
? diff
Task
Write a C program that declares your particular data structure as described in the C structure
description file. Statically initialise an instance of the data structure to the initial values as specified
in the file – use the data formats as specified in the file such as hexadecimal, decimal or octal
constants. In the main program, print out the data structure using printf formatting to make it
exactly match the provided sample output file. Note that you may need to use various formatting
options with printf to control the appearance of the output. You are expected to read about
printf and work out how to format the data so that it exactly matches the expected output.
Submit your program for automatic assessment using the lab command. Your program style may
be assessed according to the coding standards in the documents Some Important Comments on Code
Style and Systems Programming Style which are available on iLearn.
![Stage 1: Initialising a C struct and printing it out as text 3 marks] In this stage you will declare a C data structure, create an instance of it and statically initialise it Ideclare it as a static or gobal variable and initialise it in one statement using braces) You wil then print out the instance. This stage develops the following specic sklls: Declaring a Catzuct Initialising a Catruct Printing varicus data types using printf Note: Do not use bit fields in your struct. All the data types that are specified correspond to ordinary C data types. Note: The automarker checks your struct definition agairet expected ways of writing it and awards marks for correctness Field names must be exactly correct. Types should be the common C language data types as defined in ANSI C The tolowing documents on Learm may be helpful Comple, Run, Make C Progroms on Linu C Programming Notes for Doto Five Lao Your downloaded stagel.tar fle contains the following fles: files truct-description. Dlt: A simple description of the fields that are in your struct-their names and type description ini tì?lisation-specification. txt: Spectes the initial value for each tield of your struct. The inital value has to be tormatted in a specic way In your source code-this * . Decimol, Binary, tal and Hex. NoteIt makes no dference to the data that is stored inside the computerwhether you Initalsc the tiedwith decimal or the equlvalent headecimal or octal. However, 3s an exercie, we require you to make the zppropriate type converslons and the automarker wil check yur code cxpccted-output.ct:S1 expected output tile. Usc the examplc in this fic to work outwha:tormatting cptions to use npzinct. lisetul Unik ditt Task write C program, het declares your petitular data structure ?, described in the C structure description file Staticaly Initial an instanee ot the data structure to the initial values as specitics n the File-use the dete formats as specified in the file such as hesadetimel, decimal or octal constants. In the main program, print out the dets strucung printt formetting to make it exactly match the provided sample output file. Note that you may need to use various formattirg optioms withprintt to control the appearance of the output You are espected to read ebout printt and work out how to format the data so that it exectly matches the expected output Submit your program tor automatic assessment using the 1ab command. Your program style may be assessed according to the coding standerds in the documents Some important Comments on Code Style and Systems Programming Style which are available on iLearn.](https://media.cheggcdn.com/media%2F6af%2F6af2971d-e2df-4f0b-99f3-dc0312974348%2Fphp2M4yhn.png)
Expert Answer
OR

