title: C code passing struct into function Stack overflow
body: <p>Okay so I'm having an issue with a current assignment (trust me this is a minuscule part of it) as we are required to write in C code and not C++, and we are not allowed to change certain parts of code. So I have a struct defined:</p>
  
  <pre><code>    typedef struct someStruct {
      int what;
      int something[MAX];
      int another[MAX];
  } someType;
  </code></pre>
  
  <p>in main() I initialize all the values in a defined struct:</p>
  
  <pre><code>someType whatever, *whatptr;
  </code></pre>
  
  <p>EDIT:of course set the pointer to the struct, trying to simplify the code for the example It is present in my code already</p>
  
  <pre><code>whatptr = &amp;whatever;
  whatever.what = 0;
  // initialize both arrays to hold 0 at all indexes
  // Then I must call a function progRun()
  progRun();  //I need to pass struct 'whatever' in some way
  </code></pre>
  
  <p>Now progRun() looks like this:</p>
  
  <pre><code>void progRun(){
  printWhat(&amp;whatever);
  
      if (whatever.what == 0) {
      //do stuff 
      }
  }
  </code></pre>
  
  <p>I can't change anything inside this code except what parameters to pass inside the progRun() function and I can add stuff before printWhat(). I've tried changing progRun to</p>
  
  <pre><code>void progRun(someType *stptr)
  </code></pre>
  
  <p>then calling it in main as</p>
  
  <pre><code>progRun(whatptr);
  </code></pre>
  
  <p>but this causes a stack overflow issue for some reason, I've tried stepping through with a debugger and it only occurs when the function is called. Is there a better way to pass the 'whatever' struct to the function so it can be passed into progRun() and printWhat() and can access 'whatever.what'?</p>
  
  <p>Any help would be greatly appreciated! in the meantime I'll try to figure it myself if I can.</p>
  
  <p>EDIT: Something else must be wrong in the code even though everything else has compiled and ran perfectly fine until this code was added. If I can break down the code and find out what's wrong I'll update the question. And no I cannot post the whole code as it is an assignment (this isn't the goal of the assignment trust me it focuses on data forwarding and more, just need to get this basic thing working) Thank you for help everyone.</p>
  
  <p>EDIT: the MAX number used in the struct for something[MAX] and another[MAX] was extremely large ( I left my desktop that I started this project with back home, I'm currently using an old laptop that can't handle large arrays). All the answers below, and some of the stuff I used before now works fine.</p>