#include <stdio.h> #include <stdint.h> typedef union { struct { uint8_t start; uint8_t command; uint16_t data; uint8_t crc; uint8_t end; } fields; uint8_t raw[6]; } Packet; // Fill struct fields and print raw bytes void build_and_print_packet(uint8_t s, uint8_t c, uint16_t d, uint8_t crc, uint8_t e) { // Your logic here Packet pac; pac.raw[0]=s; pac.raw[1]=c; pac.raw[2]=d&0xFF; pac.raw[3]=(d>>8)&0XFF; pac.raw[4]=crc; pac.raw[5]=e; printf("%u %u %u %u %u %u",pac.raw[0],pac.raw[1],pac.raw[2],pac.raw[3],pac.raw[4] ,pac.raw[5],pac.raw[6]); } int main() { uint8_t s, c, crc, e; uint16_t d; scanf("%hhu %hhu %hu %hhu %hhu", &s, &c, &d, &crc, &e); build_and_print_packet(s, c, d, crc, e); return 0; }
Test Cases
Test Results
Input
165 1 4660 119 90
Expected Output
165 1 52 18 119 90