title: Adding and Printing elements of an array in C
body: <p>This is a function that is trying to perform the first step of converting a CFG to Chromsky Normal From by adding 0-&gt;S as a rule to the end of the list of rules. My rules are an array of characters. For some reason it will only print the array the first time and not any time after that. I want it to print the input and then result once the array has been edited. I cannot figure out why it won't print. The output is just the original input and then blank spaces.</p>
  <p>UPDATE: It will now print both times, but the output of the second print is the same as the first. It is not registering that I added ',','0','&gt;','S' as elements to the array. Am I adding the elements wrong?</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  //global variables
  char stringCFG[200];
  
  //a program to convert CFG to Chromsky Normal Form
  int main(int argc, char *argv[]){
    //intialize instance variables
    FILE *CFG;
    FILE *output;
    char ch;
    int RHS= 0;
    int isThereS= 0;
    int howManyItems= 0;
  
    CFG= fopen(argv[1], &quot;r&quot;);
    output= fopen(argv[2], &quot;w&quot;);
    
    for (int i=0; i&lt;200; i++){
        fscanf(CFG, &quot;%c&quot;, &amp;stringCFG[i]);
        howManyItems++;
        fprintf(output,&quot;%c&quot;, stringCFG[i]);
    }
    printf(&quot;\n&quot;);
  
    for(int i=0; i&lt;200; i++){
      if(stringCFG[i] == '&gt;'){
        RHS= 1;
      }
      if(stringCFG[i] == ','){
        RHS= 0;
      }
      if(RHS== 1){
        if(stringCFG[i] == 'S'){
          isThereS=1;
        }
      }
    }
  
    if(isThereS==1){
      stringCFG[howManyItems]= ',';
      howManyItems++;
      stringCFG[howManyItems]='0';
      howManyItems++;
      stringCFG[howManyItems]='&gt;';
      howManyItems++;
      stringCFG[howManyItems]='S';
      howManyItems++;
    }
   for(int i=0; i&lt;200; i++){
     fprintf(output,&quot;%c&quot;,stringCFG[i]);
    }
    fclose(CFG);
    fclose(output);
  }
  </code></pre>