SHARE
TWEET

Untitled

a guest Jun 16th, 2019 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int main()
  2. {
  3.     void *buffer = malloc(40);
  4.     int fd = open("example20.txt", O_RDONLY);
  5.     printf("the value of fd is %d n", fd);
  6.  
  7.  
  8. /* read 40 characters from the file */
  9. int bytes_read = read(fd, buffer, 40);
  10.  
  11. void *new_container = malloc(20);
  12.  
  13. /* copy from buffer, starting offset at 10 for length of 20 */
  14. memcpy(new_container, &buffer[10], 20);
  15. printf("new_container is %s n", (char *) new_container);
  16.  
  17. return 0;
  18. }
  19.      
  20. char *buffer2 = (char *) buffer;
  21. memcpy(new_container, &buffer2[10], 20);
  22.      
  23. memcpy(new_container, &buffer[10], 20);
  24.      
  25. memcpy(new_container, (char *)buffer + 10, 20);
  26.      
  27. &buffer[10]
  28.      
  29. void *buffer = malloc(40);
  30.      
  31. unsigned char *buffer = malloc(40);
  32.      
  33. memcpy(new_container, &buffer[10], 20);
  34.      
  35. char *buffer = malloc(40);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top