Starting from:

$30

Assignment 4 int cryptic calculator


Assignment 4 – (100 points)

Instructions
• Answer the questions individually. Group effort is not allowed.
• For this assignment, you are not allowed to use any library functions other than
printf.
• Ensure that your code runs on remote.cs.binghamton.edu.
• Prototypes must be provided for all functions within the header file define.h.
• Code must be appropriately commented.
• Useful resources:
1. Common linux commands: http://www.informit.com/blogs/blog.aspx?uk=The10-Most-Important-Linux-Commands
2. http://c-faq.com/
3. https://cdecl.org/
Questions
1. (40 points) Write a function int cryptic calculator(void *payload)
Where:
• If the first byte in payload is a character ’*’ representing the multiplication
operation, you are to return the product of 3 short ints starting at bytes 3, 5
and 7.
• If the first byte in the payload is a character ’/’ representing division, you
are to return the quotient when you divide int starting at byte 5 by short
int starting at byte 3. If short int starting at byte 3 is 0, you are to return
0xBAD.
1
• If the first byte is neither ’*’ or ’/’, you are to return 0xBAD.
HINT: Cast payload to an appropriate appropriate structure. Byte 1 is at &payload,
byte 3 is at &payload + 2, byte 5 is at &payload + 4 and so on.
2. (40 points) Write a function: void my memcpy(void *dst, void *src,
unsigned int num bytes) that copies num bytes from memory pointed
to by src to memory pointed to by dst. HINT: Loop num bytes times and copy
one char at a time from src to dst.
3. (20 points) Write a function: void swap strs(char *s1, char *s2)
that swaps two character strings at s1 and s2. Assume both strings s1 and s2
to be of same length.

More products