#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 start, uint8_t cmd, uint16_t data, uint8_t crc, uint8_t end) { // Your logic here Packet packet; // Fill the struct fields packet.fields.start = start; packet.fields.command = cmd; packet.fields.data = data; //LSB packet.fields.crc = crc; packet.fields.end = end; // Print the raw bytes using the array view printf("%u %u %u %u %u %u", packet.raw[0], packet.raw[1], packet.raw[2], packet.raw[3], packet.raw[4], packet.raw[5]); } 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