fork(2) download
  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. // test snprintf
  9. unsigned char a[4] = { 0x44, 0x11, 0x55, 0x66 };
  10. char buf[256] = {0};
  11. snprintf(buf, 256, "%s%02x", buf, a[0]);
  12. cout<<buf<<endl;
  13. snprintf(buf, 256, "%s%02x", buf, a[1]);
  14. cout<<buf<<endl;
  15.  
  16. // test sprintf
  17. unsigned char aa[4] = { 0x44, 0x11, 0x55, 0x66 };
  18. char buf2[256] = {0};
  19. sprintf(buf2, "%s%02x", buf2, a[0]);
  20. cout<<buf2<<endl;
  21. sprintf(buf2, "%s%02x", buf2, a[1]);
  22. cout<<buf2<<endl;
  23.  
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
44
11
44
4411