Starting from:
$30

$24

Assignment 4 Solution

Questions




(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.






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.




(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.



(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