Advertisement
zsoltizbekk

bovites

Apr 13th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char *insert( char *p, char *z, int x)
  6.  
  7. {
  8.     char *kesz;
  9.     int h1 = strlen(p),
  10.         h2 = strlen(z);
  11.  
  12.     kesz = (char *) malloc ( (h1 + h2 + 1) * sizeof(char));
  13.     memset(kesz, '\0', h1 + h2 + 1);
  14.  
  15.     if (h1 <= x)
  16.     {
  17.         strcpy(kesz, p);
  18.         strcat(kesz, z);
  19.         return kesz;
  20.     }
  21.  
  22.     strncpy(kesz, p, x);
  23.     strcat(kesz, z);
  24.     strcat(kesz, &p[x]);
  25.  
  26.     return kesz;
  27. }
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. int main()
  32. {
  33.   char s1[ 1000 ], s2[ 1000 ];
  34.   int n;
  35.   char *insert( char *, char *, int );
  36.   while ( scanf( "%s%s%d", s1, s2, &n ) != EOF )
  37.   {
  38.     char *p = insert( s1, s2, n );
  39.     puts( p );
  40.     free( p );
  41.   }
  42.   return EXIT_SUCCESS;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement