Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char *insert( char *p, char *z, int x)
- {
- char *kesz;
- int h1 = strlen(p),
- h2 = strlen(z);
- kesz = (char *) malloc ( (h1 + h2 + 1) * sizeof(char));
- memset(kesz, '\0', h1 + h2 + 1);
- if (h1 <= x)
- {
- strcpy(kesz, p);
- strcat(kesz, z);
- return kesz;
- }
- strncpy(kesz, p, x);
- strcat(kesz, z);
- strcat(kesz, &p[x]);
- return kesz;
- }
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- char s1[ 1000 ], s2[ 1000 ];
- int n;
- char *insert( char *, char *, int );
- while ( scanf( "%s%s%d", s1, s2, &n ) != EOF )
- {
- char *p = insert( s1, s2, n );
- puts( p );
- free( p );
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement