fork download
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. struct stringy {
  5. char * str;
  6. int ct;
  7. };
  8.  
  9. void set(stringy &st, char *s);
  10. void show(const stringy &st, int count=1);
  11. void show(const char s[], int count=1);
  12.  
  13. using namespace std;
  14. int main(){
  15. stringy beany;
  16.  
  17. char testing[] = "Reality isn't what it used to be.";
  18.  
  19. show(testing);
  20.  
  21. set(beany, testing);
  22. cout<<"beany.str "<<beany.str<<endl;
  23.  
  24. show(beany);
  25.  
  26. show(beany,2);
  27.  
  28. testing[0] = 'D';
  29. testing[1] = 'u';
  30.  
  31. show(testing);
  32. show(testing, 3);
  33. show("Done!");
  34.  
  35. return 0;
  36. }
  37.  
  38. void set(stringy &st, char *s){
  39. st.ct = strlen(s);
  40. st.str = new char[st.ct+1];
  41. strcpy(st.str,s);
  42. }
  43.  
  44. void show(const stringy &st, int count){
  45. while(count-- > 0){
  46. cout << st.ct << " -> " << st.str << endl;
  47. }
  48. }
  49.  
  50. void show(const char s[], int count){
  51. while(count-- > 0){
  52. cout << s << endl;
  53. }
  54. }
Success #stdin #stdout 0s 3232KB
stdin
Standard input is empty
stdout
Reality isn't what it used to be.
beany.str Reality isn't what it used to be.
33 -> Reality isn't what it used to be.
33 -> Reality isn't what it used to be.
33 -> Reality isn't what it used to be.
Duality isn't what it used to be.
Duality isn't what it used to be.
Duality isn't what it used to be.
Duality isn't what it used to be.
Done!