bogdanNiculeasa

Inversare nume prenume v1

Dec 7th, 2022
800
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int main() {
  9.     char s[21];
  10.     char result[21];
  11.     char nume[11];
  12.     char prenume[11];
  13.     // Popescu    Vasile
  14.     cin.getline(s, 21);
  15.     char* pch = strtok(s, " "); // pch contine Popescu
  16.     strcpy(nume, pch); // nume continer popescu
  17.     pch = strtok(NULL, " "); // pch contine Vasile
  18.     strcpy(prenume, pch);
  19.  
  20.     strcpy(result, prenume);
  21.     strcat(result, " ");
  22.     strcat(result, nume);
  23.  
  24.     cout << result;
  25.  
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment