Question
IN C LANGUAGE PLEASE. You do not need getopt for this program as there are no options or arguments. Call the source/executable with a useful
IN C LANGUAGE PLEASE.
You do not need getopt for this program as there are no options or arguments. Call the source/executable with a useful name relevant to the activity.
- Create a structure with variables for a character, a string pointer, an integer, and a floating point number. [Note: Use Typedef way of creating the structure].
- The structure string variable is a "char* stringp". In other words, the structure will have a pointer to a string.
- Do not initialize the structure at definition time or define any variables.
- Print size (in decimal) of one of these structures.
- Allocate memory for 5 structures of this type.
- Create 5 pointer variables to the type of structure created - name them appropriately. In other words, each pointer points to a corresponding structure.
- Print the difference between the first pointer address and the last address of the 5th structure. Print in decimal.
- First Ask the user to enter information for each of these variables one at a time. For each variable tell them what they should enter. (For example: Enter a single character or Enter a floating point number) Read in the information and put it in the structure variables using your dynamically created pointers to those structures. Hint: You can use a subroutine function and pass the pointer(s) created in step 5.
- Make sure for the read string you allocate the right amount of memory for the string read from the console - and store into the string pointer.
- Print out values for the four variables for the 5 structures using the pointers. Use other printf statements to clearly identify and separate the 5 structures.
- In addition print out the addresses of the memory locations that each string pointer points to inside the structure. Print this first.
- After printing all the values - free the memory of the structure string pointers and print the same 5 pointers to the structures again.
Output should look something like this:
Size of Structure is = AAAA
Difference between first pointer and last pointer is = BBBB
Structure 1:
Structure 1 pointer: XXXXX1
Character: h
Integer: 8
String: Caryl was here
Floating Point: 4.5
Structure 2:
Structure 2 pointer: XXXXX2
Character: x
Integer: 100
String: Juan is a friend of mine.
Floating Point: 100.2
.....
Structure 5:
Structure 5 pointer: XXXXX5
......
After free the malloc - the pointer are:
Structure 1 pointer: ZZZZZ
Structure 2 pointer: ZZZZZ
etc until Structure 5
Note: Make sure to deliver a Makefile
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started