Advertisement
apl-mhd

letter copy in a specific address

Sep 4th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.  
  7.  
  8.  
  9.     char word[100];
  10.     char wordCopy[100];
  11.  
  12.     int position, i=0, b=0, length;
  13.     char letter;
  14.  
  15.     printf("word:\n");
  16.     gets(word);
  17.  
  18.     printf("letter:\n");
  19.  
  20.     letter = getchar();
  21.  
  22.     printf("position\n");
  23.     scanf("%d", &position);
  24.  
  25.     while(word[i])
  26.         i++;
  27.  
  28.     length = i;
  29.  
  30.  
  31.     //printf("%s %c %d %d\n", word, letter, position, length);
  32.  
  33.     for( i = 0; i <= length; i++){
  34.  
  35.         if(position-1 == i){
  36.  
  37.             wordCopy[i] = letter;
  38.             b++;
  39.             wordCopy[b+i] = word[i];
  40.  
  41.             }
  42.  
  43.         else
  44.             wordCopy[b+i] = word[i];
  45.  
  46.     }
  47.  
  48.     printf("%s\n", wordCopy);
  49.  
  50.  
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement