xotohop

строки_1

May 8th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdio.h>
  3.  
  4. int main(void)
  5. {
  6.     char buf[] = "FjsdhjhfjjhhDvdnnfbcbFbkfhdjchD";
  7.     char s[strlen(buf)];
  8.     char temp;
  9.     int f_idx, d_idx;
  10.     int d_flag = 0;
  11.     strcpy(s, buf);
  12.     printf("IN string:  %s\n", s);
  13.     for (int i = 0; i < strlen(s); i++)
  14.     {
  15.         if (s[i] == 'd' && d_flag == 0)
  16.         {
  17.             d_idx = i;
  18.             d_flag = 1;
  19.         }
  20.         if (s[i] == 'f')
  21.         {
  22.             f_idx = i;
  23.         }
  24.     }
  25.     printf("%n %n\n", f_idx, d_idx);
  26.     temp = s[f_idx];
  27.     s[f_idx] = s[d_idx];
  28.     s[d_idx] = temp;
  29.     printf("OUT string: %s\n", s);
  30.     return 0;
  31. }
Add Comment
Please, Sign In to add comment