Advertisement
boyan16-z

First and last exchange

Mar 21st, 2018
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.34 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. int main() {
  6. char str[255];
  7. int i = 0,j = 0,b;
  8. printf("Input: ");
  9. gets_s(str);
  10. while (str[i] != '.') {
  11. i++;
  12. if ((str[i] == ' ') || (str[i] == '.')) {
  13. b = str[i - 1];
  14. str[i - 1] = str[j];
  15. str[j] = b;
  16. j = i + 1;
  17. }
  18. }
  19. printf("%s\n", str);
  20. return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement