title: Adding and listing an array of structs
body: <p>I've been having a few problems with using an array of structs and simply listing them and adding to them. I am not really all too sure about what's happening, I've had a search around and asked a few friends and they've suggested that it is something to do with the memory allocation and another has said that memory allocation is not needed and that there is a problem in my code.</p>
  
  <p>I have been unable to locate the problem and was wondering if anyone would be able to point me in the direction of to where I am going wrong.</p>
  
  <p>I apologies if the code doesn't look right - not really sure on how to implement it on the site.</p>
  
  <pre><code>    #include &lt;stdio.h&gt;
      #include &lt;stdlib.h&gt;
      #include &lt;string.h&gt;
  
      typedef struct data{
        int testone;
        int testtwo;
      }data;
  
      struct data _dataStore[25];
      int dataCount = 0;
  
      int addData(struct data __dataStore[dataCount]){
  
        printf("\n\t\t\tPacket Source - ");
        scanf("%i", &amp;_dataStore[dataCount].testone);
  
        printf("\t\t\tPacket Destination - ");
        scanf("%i", &amp;_dataStore[dataCount].testtwo);
  
        system("CLS");
  
        return 0;
      }
  
      void listData(struct data _dataStore[25]){
  
        int i = 0;
  
        for (i = 0; i &lt; dataCount; i++){
          printf("data stored - %i",dataCount);
          printf("%i___%i \n",          _dataStore[dataCount].testone,_dataStore[dataCount].testtwo);
        }
      }
  
  
      int main(){
  
        char choice;
  
        do{
          printf("\t\t\t Counter - %i", dataCount+1);
          printf("\n\t\t\t1 - Add data. \n");
          printf("\t\t\t2 - List data. \n");
          printf("\n\t\t\tEnter your choice - ");
  
          fflush(stdin); 
          choice = getchar();
          getchar();
  
          switch(choice){ 
            case '1':
              addData(&amp;_dataStore[dataCount]);
              dataCount++;
              system("CLS");
              break;
            case '2':
              system("CLS");
              listData(&amp;_dataStore[dataCount]);
              break;
            default:
              printf("Invalid input \n");
              break;
          }
        }while (choice != '5');
  
        return 0;
      }
  </code></pre>