title: Pass pointer array address to function and update data in the address
body: <p>I am pretty weak in understanding and working with pointers. So, Please help me here.</p>
  
  <p>My objective is to pass an array pointer's address to a function ,(i.e.) the address the pointer is pointing to, and update the values directly in the address using the '*' operator, in the function, to avoid any return values. Moreover, the length of this array has to be changed dynamically in the function to which it is passed. This is my attempt. If there's a better method to update the value of an variable, without having it returned from a function, please do mention that to help me. </p>
  
  <p>But am getting errors, as I know I am doing it wrong, but still wanted to try with what I know, since I thought the best way to learn is to do and make as many mistakes as possible. Please help me here</p>
  
  <p>This is the main function</p>
  
  <pre><code>     int main()
       {
          double *trans;
          int *rots;
          readctrls(rots,trans);
          for(int i=0;i&lt;trans.size();i++)
          {
                  cout&lt;&lt;trans[i]&lt;&lt;endl&lt;&lt;rots[i];
          }
       }
  </code></pre>
  
  <p>Here, am trying to pass the address of the pointer arrays to the function readctrls. then later, print its values. I haven't mentioned a size, cuz it will be determined later in the function.</p>
  
  <p>The function is just to read numbers from a text file, line by line and store these numbers in these 2 arrays. The readctrls function is as follows.</p>
  
  <pre><code>    void readctrls(int*&amp; rots,double*&amp; trans)
      {
          fstream inputs;
          inputs.open("input_coods.txt");
          int nol = 0,i = 0;
          string line,temp,subtemptrans,subtemprots;
          while(getline(inputs,line))
          {
                  ++nol;
          }
          cout&lt;&lt;nol&lt;&lt;endl;
          inputs.close();
          inputs.open("input_coods.txt");
          string *lines = new (nothrow) string[nol];
          trans = new double[nol];
          rots = new int[nol];
          for(int i = 0; i&lt;nol ; i++)
          {
                  getline(inputs,lines[i]);
                  temp = lines[i];
                  for(int j = 0; j&lt;temp.length() ; j++)
                  {
                          if(temp.at(j) == ' ')
                          {
                                  subtemptrans = temp.substr(0,j);
                                  subtemprots = temp.substr(j+1,temp.length()-j);
                                  trans[j] = ::atof(subtemptrans.c_str());
                                  rots[j] = atoi(subtemprots.c_str());
                          }
                  }
          }
          inputs.close();
  }
  </code></pre>
  
  <p>Thanks a lot for your help guys. I was able to understand a bit and changed the code and was able to compile now without errors. however, the value I read from file and load into the array, doesn't seem to get reflected back in the main. Am getting the correct values from the file when I print the array in the function, but am getting zeros, when I print in the main(). Please help me here.</p>
  
  <p>These are the contents of the file</p>
  
  <pre><code>     0.2 0 
       0.2 0 
       0.2 0
       0.2 0
       0.2 0
  </code></pre>
  
  <p>while print 'trans', which takes the first number every line, in the function, am getting the correct values. But while printing in the main function</p>
  
  <pre><code>    0
      0
      0
      0.2.
  </code></pre>
  
  <p>I changed the pointer to pointer reference while passing to function. Please check edit in the function code. Thanks in advance.</p>