fork(1) download
  1. #include <stdio.h>
  2. #include <arpa/inet.h>
  3.  
  4.  
  5. void testFloat() {
  6. float a[] = {1.1, 2.2, 3.3};
  7. unsigned long b[3];
  8. int len = sizeof(a) / sizeof(a[0]);
  9. int i;
  10.  
  11. for (i = 0; i < len; ++i) {
  12. // 送信時
  13. b[i] = htonl(*(unsigned long*)&a[i]);
  14.  
  15. // 受信時
  16. b[i] = ntohl(b[i]);
  17. a[i] = *(float*)&b[i];
  18. }
  19.  
  20.  
  21. for (i = 0; i < len; ++i) {
  22. printf("%f ", a[i]);
  23. }
  24. printf("\n");
  25.  
  26. }
  27.  
  28. int main(int ac, char **av) {
  29. testFloat();
  30. }
Success #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
1.100000 2.200000 3.300000