Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include<iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5. void insertComma(char *s);
  6.  
  7. int main()
  8. {
  9.     char newS[100];
  10.     cin.getline (newS,100);
  11.     insertComma(newS);
  12.     cout << newS;
  13.     system("pause");
  14.     return 0;
  15. }
  16. void insertComma(char *s) {
  17.     int j = 0;
  18.     int size = strlen(s);
  19.     char newS[100];
  20.     for (int i = 0; i < size; i++, j++) {
  21.         newS[j] = s[i];
  22.         if (isspace(s[i]) != 0) {
  23.             j++;
  24.             newS[j] = ',';
  25.  
  26.         }
  27.  
  28.     }
  29.     newS[j] = '\0';
  30.     strcpy_s(s, strlen(newS) + 1, newS);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement