title: My program does not work without printf
body: <p>I have an interesting problem that I can't figure out.
  My program doesn't work without printf</p>
  
  <pre><code>printf("",L[i-1][j][k],L[i][j-1][k],L[i][j][k-1],L[i-1][j][k-1],L[i-1][j-1][k],L[i][j-1][k-1],L[i-1][j-1][k-1]);
  </code></pre>
  
  <p>I don't mean printf("%s",S); under main, I mean printf under getLCS function. With printf the output of this program is "fskxft" the proper answer. Without printf the output of the program is "(w"
  How can it be possible?
  Here is my code:</p>
  
  <pre><code>    #include&lt;stdio.h&gt;
      #include&lt;stdlib.h&gt;
      #include&lt;string.h&gt;
  
      void findLCS(char*, char*, char*, int, int, int);
      int*** allocMem(int, int, int);
      void fillMatrix(char*, char*, char*, int***, int, int, int);
      char* getLCS(char*, int***, int, int, int);
      int findMax(int, int, int);
      void freeMem(char*, char*, char*, int***, char*, int, int);
  
      int main()
      {
          char* X = malloc(1000*sizeof(char));
          char* Y = malloc(1000*sizeof(char));
          char* Z = malloc(1000*sizeof(char));
          X = "bccmzzzxxyizqnlovffmrudbcywrsqkjcxhexftf";
          Y = "kcftkzdlsyjkxkjxfcjhbfkkdwcrgnjdxtgkaxhm";
          Z = "vihfjvbvsklwyxyzobeztllmvfdgsvekcvtqugjw";
  
          int m = strlen(X);
          int n = strlen(Y);
          int o = strlen(Z);
  
          int*** L = allocMem(m,n,o);
          fillMatrix(X,Y,Z,L,m,n,o);
          char *S = getLCS(Z,L,m,n,o);
          printf("%s",S);
          freeMem(X,Y,Z,L,S,m,n);
  
        return 0;
      }
  
      int*** allocMem(int m, int n, int o)
      {
          int x = m+1, y = n+1, z = o+1;
          int i, j;
  
          //Allocating Memory
          int *entries = malloc(x * y * z * sizeof(entries));
          int ***L = malloc(x * sizeof(int **));
          for(i = 0; i &lt; x; i++)
          {
              L[i] = malloc(y * sizeof(int *));
              for(j = 0; j &lt; y; j++)
              {
                  L[i][j] = entries + (i * y * z) + (j * z);
              }
          }
          return L;
      }
      void fillMatrix(char* X, char* Y, char* Z, int*** L, int m, int n, int o)
      {
          int i, j, k;
          //Filling the LCS matrix
          for (i=0; i&lt;=m; i++)
          {
              for (j=0; j&lt;=n; j++)
              {
                  for(k=0; k&lt;=o; k++)
                  {
                      if (i == 0 || j == 0 || k == 0)
                      {
                          L[i][j][k] = 0;
                      }
                      else if ((X[i-1] == Y[j-1]) &amp;&amp; (Y[j-1] == Z[k-1]))
                      {
                          L[i][j][k] = L[i-1][j-1][k-1] + 1;
                      }
                      else
                      {
                          L[i][j][k] = findMax(L[i-1][j][k], L[i][j-1][k], L[i][j][k-1]);        
                      }
                  }
              }
          }
      }
      char* getLCS(char* Z, int*** L, int m, int n, int o)
      {
          int i, j, k;
          int l = L[m][n][o];
          char* S = malloc(l*sizeof(*S));
          int c= l-1;
          int jj, kk;
          for (i=m; i&gt;0; i--)
          {
              for (j=n; j&gt;0; j--)
              {
                  if(j &gt; jj)
                  {
                      j = jj;
                  }
                  for(k=o; k&gt;0; k--)
                  {
                      if(k &gt; kk)
                      {
                          k = kk;
                      }
                      printf("",L[i-1][j][k],L[i][j-1][k],L[i][j][k-1],L[i-1][j][k-1],L[i-1][j-1][k],L[i][j-1][k-1],L[i-1][j-1][k-1]);
                      if(L[i-1][j][k] == c &amp;&amp; L[i][j-1][k] == c &amp;&amp; L[i][j][k-1] == c &amp;&amp; L[i-1][j][k-1] == c &amp;&amp; L[i-1][j-1][k] == c &amp;&amp; L[i][j-1][k-1] == c &amp;&amp; L[i-1][j-1][k-1] == c &amp;&amp; L[i][j][k] == c+1)
                      {
                          S[c]=Z[k-1];
                          c--;
                          i=i-1;
                          j=j-1;
                          k=k-1;
                          jj = j;
                          kk = k;
                      }
                  }
              }
          }
          S[l] = '\n';
          return S;
      }
  
      int findMax(int a, int b, int c)
              {
          int max = a;
          if(b&gt;max)
          {
              max = b;
          }
          if(c&gt;max)
          {
              max = c;
          }
          return max;
      }
  
      void freeMem(char* X, char* Y, char* Z, int*** L, char* S, int m, int n)
      {
          int i, j;
          int x = m+1, y = n+1;
          free(X);
          free(Y);
          free(Z);
          for(i = 0; i &lt; x; i++)
          {
              for(j = 0; j &lt; y; j++)
              {
                  free(L[i][j]);
              }
              free(L[i]);
          }
          free(L);
      }
  </code></pre>