CHARACTER_ARG


SUBMITTED BY: davindran21

DATE: Oct. 12, 2016, 1:59 a.m.

FORMAT: Text only

SIZE: 2.2 kB

HITS: 1224

  1. # include <cstdlib>
  2. # include <iostream>
  3. # include <cstring>
  4. using namespace std;
  5. int main ( );
  6. void fred ( string *name );
  7. //****************************************************************************80
  8. int main ( )
  9. //****************************************************************************80
  10. //
  11. // Purpose:
  12. //
  13. // MAIN is the main program for CHARACTER_ARG.
  14. //
  15. // Licensing:
  16. //
  17. // This code is distributed under the GNU LGPL license.
  18. //
  19. // Modified:
  20. //
  21. // 25 May 2013
  22. //
  23. // Author:
  24. //
  25. // John Burkardt
  26. //
  27. {
  28. string name;
  29. cout << "\n";
  30. cout << "CHARACTER_ARG:\n";
  31. cout << " Demonstrate how a C function can return character data\n";
  32. cout << " through the argument list.\n";
  33. cout << "\n";
  34. cout << " Our main program declares a string:\n";
  35. cout << " string name;\n";
  36. cout << " then calls function fred() with the ADDRESS of the string:\n";
  37. cout << " fred ( &name );\n";
  38. cout << " Function fred receives its argument as\n";
  39. cout << " void fred ( string *name )\n";
  40. cout << " It sets a value to the string:\n";
  41. cout << " *name = \"ob_data.txt\" );\n";
  42. cout << " The main program now has a string stored in name.\n";
  43. fred ( &name );
  44. cout << "\n";
  45. cout << " The value of name is now = \"" << name << "\".\n";
  46. cout << "\n";
  47. cout << "CHARACTER_ARG:\n";
  48. cout << " Normal end of execution.\n";
  49. return 0;
  50. }
  51. //****************************************************************************80
  52. void fred ( string *name )
  53. //****************************************************************************80
  54. //
  55. // Purpose:
  56. //
  57. // FRED returns character data through one of its arguments.
  58. //
  59. // Licensing:
  60. //
  61. // This code is distributed under the GNU LGPL license.
  62. //
  63. // Modified:
  64. //
  65. // 25 May 2013
  66. //
  67. // Author:
  68. //
  69. // John Burkardt
  70. //
  71. // Parameter:
  72. //
  73. // Input, string *NAME, the address of the address of a character.
  74. // The value *NAME is the address of a character, and can be set
  75. // to the address of a string of interest to the user.
  76. //
  77. {
  78. *name = "ob_data.txt";
  79. return;
  80. }

comments powered by Disqus