title: Removing Garbage value in array in C
body: <p>I have a garbage problem in my array in C, that I can't solve and I have used the  <code>memset</code> function for this but this is not useful to me. how can I solve this problem. If I run this code in Code Block or other PC then this is not run completely.</p>
  
  <p>Here is my code:</p>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;conio.h&gt;
  #include &lt;string.h&gt;
  
  int main() {
      clrscr();
      int a, b, len = 0, x, i = 0, j, match, misMatch, gapPenalty, sim, m1, m2, m3;
      char ch;
      char *seq1 = (char *)malloc(100 * sizeof(char));
      char *seq2 = (char *)malloc(100 * sizeof(char));
      char *s1 = (char *)malloc(100 * sizeof(char));
      char *s2 = (char *)malloc(100 * sizeof(char));
  
      /*memset(seq1, 0, strlen(seq1) - 1);
      memset(seq2, 0, strlen(seq2) - 1);
      memset(s1, 0, strlen(s1) - 1);
      memset(s2, 0, strlen(s2) - 1);*/
  
      int **matrix;
      int **back;
  
      FILE *inputFile;
      inputFile = fopen("in.txt", "r");
      printf("Enter Match Point : ");
      scanf("%d", &amp;match);
  
      printf("Enter Mismatch Point : ");
      scanf("%d", &amp;misMatch);
  
      printf("Enter Gap Point : ");
      scanf("%d", &amp;gapPenalty);
  
      while (fscanf(inputFile,"%s\n%s", seq1, seq2) != EOF);
  
      a = strlen(seq1);
      b = strlen(seq2);
      for (j = 0; j &lt;= strlen(seq2); j++) {
          for (i = 0; i &lt;= strlen(seq1); i++) {
             if (i == 0 || j == 0) {
                 if (i == 0) {
                     matrix[j][i] = j * gapPenalty;
                     back[j][i] = 0;
                 }
                 if (j == 0) {
                     matrix[j][i] = i * gapPenalty;
                     back[j][i] = 0;
                 }
             } else {
                 if (seq1[i - 1] == seq2[j - 1]) {
                     sim = match;
                 } else {
                     sim = misMatch;
                 }
                 m1 = matrix[j - 1][i - 1] + sim;
                 m2 = matrix[j - 1][i] + gapPenalty;
                 m3 = matrix[j][i - 1] + gapPenalty;
                 if (m1 &gt; m2) {
                     if (m1 &gt; m3) {
                         matrix[j][i] = m1;
                         back[j][i] = 1;
                     } else {
                         matrix[j][i] = m3;
                         back[j][i] = 3;
                     }
                 } else {
                     if (m2 &gt; m3) {
                         matrix[j][i] = m2;
                         back[j][i] = 2;
                     } else {
                         matrix[j][i] = m3;
                         back[j][i] = 3;
                     }
                 }
             }
          }
      }
      printf("%s", seq1);
      printf("\n");
      printf("%s", seq2);
      printf("\n");
  
      if (a &gt; b) {
          len = a;
      } else {
          len = b;
      }
  
      for (x = 0; x &lt; len; x++) {
          if (back[b][a] == 1) {
              s1[x] = seq1[a - 1];
              s2[x] = seq2[b - 1];
              a = a - 1;
              b = b - 1;
          } else if(back[b][a] == 2) {
              s1[x] = seq1[a - 1];
              s2[x] = '-';
              a = a - 1;
          } else {
               s1[x] = '-';
               s2[x] = seq2[b - 1];
               b = b - 1;
          }
      }
      for (j = 0; j &lt;= strlen(seq2); j++) {
          for (i = 0; i &lt;= strlen(seq1); i++) {
              printf("%d ", matrix[j][i]);
          }
          printf("\n");
      }
  
      printf("\n");
      for (j = 0; j &lt;= strlen(seq2); j++) {
          for (i = 0; i &lt;= strlen(seq1); i++) {
              printf("%d ", back[j][i]);
          }
          printf("\n");
      }
  
      printf("\n");
      printf("%s", s1);
      printf("\n");
      printf("%s", s2);
      printf("\n");
  
      free(s1);
      free(s2);
      free(matrix);
      free(back);
      getch();
      return 0;
  }
  </code></pre>