fork download
  1. #include <stdio.h>
  2. #include <sys/uio.h>
  3.  
  4. int main(void) {
  5. char *str0 = "hello ";
  6. char *str1 = "world ";
  7. int x=5;
  8. //char ch = 'a';
  9. struct iovec iov[3];
  10. ssize_t nwritten;
  11.  
  12. iov[0].iov_base = str0;
  13. iov[0].iov_len = strlen(str0);
  14. iov[1].iov_base = str1;
  15. iov[1].iov_len = strlen(str1);
  16. iov[2].iov_base = (&x);
  17. iov[2].iov_len = sizeof(x);
  18.  
  19. nwritten = writev(1, iov, 3);//1 for stdout
  20. printf("\n number written=%d\n",nwritten);
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
hello world 
 number written=16