title: Why is this program(rather the segment) crashing the whole program
body: <p>I have been scratching my head to figure out why is my program is crashing. My aim was to scan a string and get frequency of each sub string !</p>
  
  <p>The Real part where the program is crashing (M is a map of string,int type)
  My Input: the string is "abab" and the program crashes when i=0 and j is equal to 3 just at the M[e]++ statement!</p>
  
  <pre><code>    for(i=0;str[i];i++)
          {
  
              char temp[5001];
              k=0;
              cout&lt;&lt;str[i]&lt;&lt;endl;
              for(j=i;str[j];j++)
                  {
                      temp[k]=(char)str[j];
                      k++;
                      temp[k]='\0';
                      string e(temp);
                      M[e]++;
                      cout&lt;&lt;j&lt;&lt;endl;
                  }
          }
  </code></pre>
  
  <p><strong>MAIN Method</strong> </p>
  
  <pre><code>    int main()
      {
      ini();
      int t,N,i,j,Q,buff,k=0;
      char str[5001];
      scanf("%d",&amp;t);
      map &lt;string ,int &gt; M;
      map &lt;string , int &gt;::iterator ii;
      for(;t--;)
      {
          scanf("%d%d",&amp;N,&amp;Q);
          scanf(" %s",str);
          for(i=0;str[i];i++)
              {
  
                  char temp[5001];
                  k=0;
                  cout&lt;&lt;str[i]&lt;&lt;endl;
                  for(j=i;str[j];j++)
                      {
                          temp[k]=(char)str[j];
                          k++;
                          temp[k]='\0';
                          string e(temp);
                          M[e]++;
                          cout&lt;&lt;j&lt;&lt;endl;
                      }
              }
          for(ii=M.begin();ii!=M.end();++ii)
                  F[ii-&gt;second]++;
          F2[N]=F[N]%MOD;
          for(i=N;i&gt;=1;i--)
              if(F[i])
                  for(j=i-1;j&gt;=1;j--)
                      F2[j]=(F[j]+((long long)F[i]%MOD*C(F[i],j)%MOD)%MOD)%MOD;
          for(i=0;i&lt;Q;i++)
             {
                  scanf("%d",&amp;buff);
                  printf("%d\n",F2[buff]);
              }
          }
          return 0;
      }
  </code></pre>
  
  <p>Note </p>
  
  <pre><code>int F[5001],F2[5001];
  </code></pre>
  
  <p>are declared globally too.</p>