title: C/C++ reading and writing long strings to files
body: <p>I have a list of cities that I'm formatting like this:</p>
  
  <pre><code>{town, ...}, 
  {...},
  ...
  </code></pre>
  
  <p>Reading and building each town and creating town1, town2,.... works
  The problem is when I output it, 1st line works {town, ...}, but the second line crashes.
  Any idea why?</p>
  
  <p>I have [region] [town] (excel table).</p>
  
  <p>So each region repeats by how many towns are in it.
  Each file has 1 region/town per line.</p>
  
  <p>judete contains each region repeated 1 time.</p>
  
  <pre><code>AB
  SD
  PC
  ....
  </code></pre>
  
  <p>orase contains the towns list.</p>
  
  <pre><code>town1
  town2
  ....
  </code></pre>
  
  <p>orase-index contains the region of each town</p>
  
  <pre><code>AB
  AB
  AB
  AB
  SD
  SD
  SD
  PC
  PC
  ...
  </code></pre>
  
  <p>I want an output like this {"town1", "town2", ...} and each row (row 5) contains the town that belong to the region from judete at the same row (row 5).</p>
  
  <p>Here's my code:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  
  char judet[100][100];
  char orase[50][900000];
  char oras[100], ceva[100];
  
  void main ()
  {
  
      int i=0, nr;
      FILE *judete, *index, *ORASE, *output;
      judete = fopen("judete.txt", "rt");
      index = fopen("orase-index.txt", "rt");
      ORASE = fopen("orase.txt", "rt");   
      output = fopen("output.txt", "wt");
  
      while( !feof(judete) )
      {
          fgets(judet[i], 100, judete);
          i++;
      }
  
      nr = i;
      char tmp[100];
      int where=0;
  
      for(i=0;i&lt;nr;i++)
          strcpy(orase[i],"");
  
      while( !feof(index) )
      {
          fgets(tmp, 100, index);
          for(i=0;i&lt;nr;i++)
          {
              if( strstr(judet[i], tmp) )
              {
                  fgets(oras, 100, ORASE);
                  strcat(ceva, "\"");
                  oras[strlen(oras)-1]='\0';
                  strcat(ceva, oras);
                  strcat(ceva, "\", ");
                  strcat(orase[i], ceva);
                  break;
              }
  
          }
      }
  
  
      char out[900000];
  
      for(i=0;i&lt;nr;i++)
      {
          strcpy(out, "");
          strcat(out, "{");
          strcat(out, orase[i]); //fails here
          fprintf(output, "%s},\n", out);
      }
  
  }
  </code></pre>
  
  <p>The result I get from running the code is:</p>
  
  <blockquote>
    <p>Unhandled exception at 0x00D4F7A9 (msvcr110d.dll) in orase-judete.exe: 0xC0000005: Access violation writing location 0x00A90000.</p>
  </blockquote>