title: Giving a char array a default value with a constructor in a class c++
body: <p>I'm writing a little program that takes input from the user. The input being an integer, for the number of the student, 2 double numbers as grades, and the field of study, which has to be a character array of maximum size 20.
  Now when writing the class, I'm not quite sure how to give the character array a default value in the constructor.</p>
  
  <p>This is what I've written with the class and constructor.</p>
  
  <pre><code>class nemandi
  {
  public:
      nemandi(int num, double g1, double g2, char field[]);
      void birta();
      friend bool operator &lt;(nemandi&amp; nem1, nemandi&amp; nem2);
  private:
      int studentNumber;
      double grade1;
      double grade2;
      double medaltal();
      char fieldOfStudy[20];
  };
  
  
  nemandi::nemandi(int num, double g1, double g2, char field[])
  {
      studentNumber = num;
      grade1 = g1;
      grade2 = g2;
      fieldOfStudy[20] = field[20];
  }
  </code></pre>
  
  <p>This doesn't work, and I haven't been able to find a solution to this online. Can anyone point me in the right direction of how to give the char array a default value in the constructor??</p>
  
  <p>Thanks in advance !</p>
  
  <p>EDIT: Replacing <code>fieldOfStudy[20] = field[20];</code> with <code>memcpy(fieldOfStudy, field, sizeof(fieldOfStudy));</code> did the trick ! Thanks for helping out guys :)</p>