out: Monday, April 7, 2024
due: Wednesday, April 9, 2024 by 10:00 am,
No late exercises accepted.
Goals: Write a program that uses structs, typedef, and dynamic memory allocation (malloc/free).
Description: Your job is to write a C program that does the following:
Point3d
, which contains uint16_t
fields for x, y, and z
coordinates. AllocatePoint3d
that accepts
three uint16_t
values as arguments, mallocs space for a Point3d
, assigns
those three arguments to the x, y, and z fields, and returns (a
pointer to) the malloc'ed Point3d
.
AllocatePoint3d
.
For the purposes of this exercise, it is enough for you to write
code that simply allocates a struct by calling AllocatePoint3d
and verifies that the struct
members contain the correct values.
Your "test" should print an appropriate message if something is wrong;
if all is well your program should terminate silently.
Make sure your
main function frees any memory that AllocatePoint3d
allocates.
Hint: Don't make assumptions about what
AllocatePoint3d
does, even though you implement it.
Imagine that your main
is testing an implementation of
AllocatePoint3d
that is implemented by another programmer.
Your code must:
ex3.c
that compiles with the command gcc -Wall -g -std=c17 -o ex3 ex3.c
--
do not submit a Makefile. .c
file with your name,
and CSE or UW email address.You should submit your exercise using the Gradescope dropbox linked on the course resources web page.