Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum { BUFFER_SIZE = 10 };
- char str1[BUFFER_SIZE];
- char str2[]="abcdefghijklmn";
- strncpy(str1,str2, BUFFER_SIZE); /* limit number of characters to be copied */
- // We need to set the limit to BUFFER_SIZE, so that all characters in the buffer
- // are set to '\0'. If the source buffer is longer than BUFFER_SIZE, all the '\0'
- // characters will be overwritten and the copy will be truncated.
- if (str1[BUFFER_SIZE-1] != '\0') {
- /* buffer was truncated, handle error? */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement