Advertisement
informaticage

Substitute string

Mar 4th, 2021
753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.23 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4.   char str[100] = "Hello, world!";
  5.   char sub = 'l', rep = 'k';
  6.  
  7.   for(size_t i = 0; str[i] != '\0'; i++) {
  8.     str[i] = str[i] == sub ? rep : str[i];
  9.   }
  10.  
  11.   printf("%s", str);
  12.   return 0;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement