fork(2) download
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. char str[] = "3F4C5D026611, 3F4C5D026622, 3F4C5D026633";
  6.  
  7. union address
  8. {
  9. uint64_t ull;
  10. uint8_t bytes[8];
  11. };
  12.  
  13. address addresses[12];
  14.  
  15.  
  16. char * ptr = str;
  17. uint8_t counter = 0;
  18.  
  19. while( *ptr && counter < 12 )
  20. {
  21. addresses[counter++].ull = strtoull( ptr, &ptr, 16 );
  22. if ( *ptr ) ptr++; // if end of string not reached, increase pointer to skip ','
  23. }
  24.  
  25.  
  26. for ( uint8_t i = 0; i < counter; i++ )
  27. {
  28. address * a = &addresses[i];
  29. printf( "address %hhu = %02X:%02X:%02X:%02X:%02X:%02X\n",
  30. i,
  31. a->bytes[5],
  32. a->bytes[4],
  33. a->bytes[3],
  34. a->bytes[2],
  35. a->bytes[1],
  36. a->bytes[0]
  37. );
  38. }
  39.  
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5368KB
stdin
Standard input is empty
stdout
address 0 = 3F:4C:5D:02:66:11
address 1 = 3F:4C:5D:02:66:22
address 2 = 3F:4C:5D:02:66:33