hash_map crashing in c++ stl
<p>i am relatively experienced in Java coding but am new to C++.
I have written the following C++ code as solution to the USACO training problem which I have reproduced at <a href="http://jatinbatra.blogspot.com/2009/12/usaco-training-pages-problem-gift1.html" rel="nofollow">this url</a></p>

<p>This code looks fine to me.
However it crashes on the sample test case given.
On isolating the error, I found that if the second for loop is not run for the last iteration (I mean like in the sample test case, n = 5, so I run the loop only till i = 3 instead of i = 4), then it doesn't crash (and produces the expected output).
Maybe the error is somewhere else, I can't detect it.</p>

<p>Any ideas are welcome.
Thanks in advance.
Please excuse me for the slightly unwieldy formatting of the code (this is my first forum post). The files included are stdlib.h, stdio.h and hash_map.h
`</p>

<pre><code>#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;hash_map.h&gt;

struct eqstr
{
  bool operator()(const char* s1, const char* s2) const
  {
    return strcmp(s1, s2) == 0;
  }
};


int main(int argc, char** argv) {

    FILE *fin = fopen("gift1.in", "r");
    FILE *fout = fopen("gift1.out", "w");


    hash_map&lt;const char*, int, hash&lt;const char*&gt;, eqstr&gt; table;

    int n;
    fscanf(fin,"%d",&amp;n);
    char name[15];
    char people[10][15];

    for(int i = 0; i &lt; n; i++){
        fscanf(fin,"%s",name);
        strcpy(people[i],name);
        table[people[i]] = 0;
    }//ifor

    for(int i = 0; i &lt; n; i++){
        fscanf(fin,"%s",name);
        int money;
        fscanf(fin,"%d",&amp;money);
        int friends;
        fscanf(fin,"%d",&amp;friends);
        char fname[15];
        int amt = money/friends;
        for(int j = 0; j &lt; friends; j++){
            fscanf(fin,"%s",fname);
            table[fname] = table[fname] + amt;
        }//jfor
        table[name] = table[name] - friends*amt;
    }//ifor

    for(int i = 0; i &lt; n; i++)
        fprintf(fout,"%s %d\n",people[i],table[people[i]]);

    return (EXIT_SUCCESS);
}
</code></pre>

<p>`</p>
