Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. struct stringy // structure definition
  5. {
  6. char *str;
  7. int ct;
  8. };
  9.  
  10. void set(stringy &beany, const char *testing); // function definition
  11.  
  12. int main()
  13. {
  14. stringy beany;
  15. char testing[] = "Reality isn't what it used to be.";
  16. set(beany, testing); // function call
  17. return 0;
  18. }
  19.  
  20. void set(stringy &beany, const char *testing) // function prototype
  21. {
  22. int i=0;
  23. while (*(testing+i) != '') // this loop counts the number of characters
  24. {
  25. i++;
  26. std::cout << i << "n";
  27. }
  28. beany.str = new char[i]; // dynamic storage allocation
  29. std::cout << strlen(beany.str); // printing the length of the string
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement