ivanakarpuzova

Вметнување на еден стринг во друг

Dec 11th, 2016
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void promena(char *niza, char *niza1, int n)
  5. {
  6.  
  7.     strcat(niza1,niza+n);
  8.     niza[n]='\0';
  9.     strcat(niza,niza1);
  10.  
  11. }
  12.  
  13. int main ()
  14. {
  15.     char niza[100],niza1[100];
  16.     int n;
  17.     gets(niza);
  18.     gets(niza1);
  19.     scanf("%d",&n);
  20.     promena(niza,niza1,n);
  21.     puts(niza);
  22.  
  23.  
  24. }
  25.  
  26. /*
  27. #include <stdio.h>
  28. #include <string.h>
  29.  
  30.  
  31.  
  32. int main(){
  33.  
  34.     char str1[100], str2[100];
  35.     int position;
  36.     char sePoslePosition[100];
  37.  
  38.     gets(str1);        
  39.     gets(str2);    
  40.     scanf("%d", &position);    
  41.  
  42.     char str3[100];
  43.     int i;
  44.     int index = 0;
  45.  
  46.     for(i = position - 1; i < strlen(str1); i++) {
  47.         sePoslePosition[index] = str1[i];
  48.         ++index;
  49.     }
  50.    
  51.     for(i = 0; i < position - 1; i++) {        
  52.         str3[i] = str1[i];
  53.     }
  54.    
  55.     strcat(str3, " ");
  56.     strcat(str3, str2);
  57.     strcat(str3, sePoslePosition);
  58.     printf("%s", str3);
  59.  
  60. }
  61. */
Advertisement
Add Comment
Please, Sign In to add comment