Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. enum { BUFFER_SIZE = 10 };
  2. char str1[BUFFER_SIZE];
  3. char str2[]="abcdefghijklmn";
  4.  
  5. strncpy(str1,str2, BUFFER_SIZE); /* limit number of characters to be copied */
  6. // We need to set the limit to BUFFER_SIZE, so that all characters in the buffer
  7. // are set to '\0'. If the source buffer is longer than BUFFER_SIZE, all the '\0'
  8. // characters will be overwritten and the copy will be truncated.
  9.  
  10. if (str1[BUFFER_SIZE-1] != '\0') {
  11. /* buffer was truncated, handle error? */
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement