Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main(){
- int len=7;
- // No errors with this:
- //char s1[len];
- //char s2[len];
- // Valgrind error with this:
- char *s1 = malloc(len * sizeof(char));
- char *s2 = malloc(len * sizeof(char));
- strcpy(s1, "String1");
- strcpy(s2, "String2");
- size_t new_size = strlen(s1) + strlen(s2) + 1;
- strncat(s1, s2, new_size);
- puts(s1);
- free(s1);
- free(s2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement