Advertisement
jacknpoe

copypchar (copy of a string pointer of char)

Nov 6th, 2013
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include<cstring>
  2. #include<cstdlib>
  3. #include<iostream>
  4. #include<locale>
  5.  
  6. char* copypchar( char* data) {
  7.     char *buffer; long size;
  8.     size = strlen( data);
  9.     if( ( buffer = (char *) malloc( ( size + 1) * sizeof( char)) ) == NULL) return NULL;
  10.     memcpy( buffer, data, size+1);
  11.     return buffer;
  12. }
  13.  
  14. int main() {
  15.     char buffer[201], *nome;
  16.     setlocale( LC_ALL, "");     // equal caracters in prompt
  17.     std::cout << "Nome: ";
  18.     std::cin.getline( buffer, 200);
  19.     nome = copypchar( buffer);
  20.     std::cout << "Tamanho do nome: " << strlen( nome) << "\n";
  21.     std::cout << "Nome: " << nome;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement