Advertisement
daniv1

c-style

Jul 24th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3.                               Online C++ Compiler.
  4.                Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <iostream>
  10.  
  11. unsigned stringlen(const char *str)
  12. {
  13.     unsigned cnt = 0;
  14.     while( *str != '\0')
  15.     {
  16.         str++;
  17.         cnt++;
  18.     }
  19.     return cnt;
  20.    
  21. }
  22. void strcat(char *to, const char *from)
  23. {
  24.    
  25. }
  26.  
  27.  
  28. int main()
  29. {
  30.     char a[] = "C-style string";
  31.     char b[] = "JOPA";
  32.    
  33.    
  34.     char *to = &a[0];
  35.     char *from = &b[0];
  36.     unsigned lenA = stringlen(a);
  37.     unsigned lenB = stringlen(b);
  38.    // to+= lenA;
  39.     for(int i = 0 ; i!= lenB ; i++)
  40.     {
  41.         *to=*from;
  42.         to++;
  43.         from++;
  44. }
  45. to-= lenB + 1;
  46.     for(int i = 0; i<= stringlen(a); i++)
  47.     {
  48.         std::cout<<*to;
  49.         to++;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement