fork download
  1. #include <cstddef>
  2. #include <iostream>
  3.  
  4. void example_strcpy(char *dest, const char *src)
  5. {
  6. std::size_t i=0;
  7.  
  8. do
  9. {
  10. dest[i] = src[i];
  11. std::clog << "dest[" << i << "] := '";
  12.  
  13. if (src[i] == '\0')
  14. std::clog << "\\0' (NUL character)";
  15. else
  16. std::clog << src[i] << '\'';
  17.  
  18. std::clog << '\n';
  19. }
  20. while (src[i++] != '\0');
  21. }
  22.  
  23. int main()
  24. {
  25. char name[40];
  26.  
  27. example_strcpy(name, "Wolverine");
  28. std::cout << "name is: " << name << std::endl;
  29. }
  30.  
Success #stdin #stdout #stderr 0s 3340KB
stdin
Standard input is empty
stdout
name is: Wolverine
stderr
dest[0] := 'W'
dest[1] := 'o'
dest[2] := 'l'
dest[3] := 'v'
dest[4] := 'e'
dest[5] := 'r'
dest[6] := 'i'
dest[7] := 'n'
dest[8] := 'e'
dest[9] := '\0' (NUL character)