title: Pointer to a C-String?
body: <p>For an intro to CS assignment, I am writing a C++ program in Visual Studio 2010 which returns an integer and accepts a pointer to a C-string as an argument. I know that I need to make a function besides an int main to succeed, but I am not exactly sure about how to initialize a char pointer array which points to a predefined char array, if possible.  </p>
  
  <p>The purpose of this program is to get a comment from a user within a predefined limit then inform said user how many characters (including whitespace) that comment is. </p>
  
  <p>The error is: a value of type "char" cannot be assigned to an entity of type "char *";</p>
  
  <p>Here is my program that does not compile: </p>
  
  <pre><code>#include "stdafx.h"
   #include &lt;iostream&gt;
   #include &lt;string&gt;
   #include &lt;conio.h&gt;
   using namespace std;
  
   //function protoype
   void evalStr(char arr[]);
  //variable
  int length;
  
  
  //main function
  int main()
  {
      const int SIZE = 201;
      char arr[SIZE];
      char *str[SIZE];
      cout &lt;&lt; "Please enter a comment under " &lt;&lt; (SIZE - 1) &lt;&lt; " characters to calculate it's length: ";
      *str = arr[SIZE];
  
      cin.getline(arr, SIZE);
  
  
      length = strlen(*str);
      evalStr(arr);
  
      system("PAUSE");
      return 0;
  }
  //function defintion
  /*  get the string
      count the number of characters in the string
      return that number
  
  */
  void evalStr(char arr[])
  {
      printf("The length of the entered comment is %d characters\n", length);
  }
  </code></pre>
  
  <p>If there is a general method to utilizing char pointer arrays or perhaps pointers to strings, this code could be redone to return the value of the string instead of utilizing that printf statement. What all am I doing wrong?</p>
  
  <p>Edit: Here is an updated version of this program that compiles, runs, and informs the user if the character limit is reached or exceeded. </p>
  
  <pre><code>// Accept a pointer to a C-string as an argument 
  // Utilize the length of C-string in a function. 
  // Return the value of the length
  // Display that value in a cout statement.
  #include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;conio.h&gt;
  using namespace std;
  
  
  //variables
  const int SIZE = 201;
  int length;
  
  char arr[SIZE];
  char *str;
  
  
  //main function
  int main()
  {
      str = &amp;arr[0];
  
      // Size - 1 to leave room for the NULL character
      cout &lt;&lt; "Please enter a comment under " &lt;&lt; (SIZE - 1) &lt;&lt; " characters to calculate it's length: ";
  
  
      cin.getline(arr, SIZE);
  
  
      length = strlen(str);
      if (length == (SIZE - 1))
      {
          cout &lt;&lt; "Your statement has reached or exceeded the maximum value of " 
               &lt;&lt; length &lt;&lt; " characters long.\n";
      }
      else
      {
      cout &lt;&lt; "Your statement is ";
      cout &lt;&lt; length &lt;&lt; " characters long.\n";
      }
  
  
      system("PAUSE");
      return 0;
  }
  //function defintion
  /*  get the string
      count the number of characters in the string
      return that number
  
  */
  int countChars(int)
  {
      length = strlen(str);
  
      return length;
  }
  </code></pre>