title: App crashes when the input data to write on txt is bigger than 16kb (C programming)
body: <p>I'm trying to make a program which gets inputs from txt file (coordinates like x1,x2) and store it on element to write in SVG format. The code I wrote below works actually. The problem is when I get input bigger than 16kb, while writing on svg file application crashes. So I cannot find the problem actually. It should be about "strcat(str_joined, svg[i].xy);" this since I'm joining so much string into one string variable.</p>
  
  <p>Input Example : </p>
  
  <pre><code>339, 52
  339, 52
  339, 52
  338, 53
  338, 53
  337, 54
  337, 54
  337, 54
  337, 55
  337, 55
  336, 56
  336, 56
  336, 56
  336, 57
  335, 57
  335, 56
  334, 56
  334, 56
  333, 56
  332, 56
  332, 56
  331, 56
  331, 56
  330, 56
  330, 56
  329, 56
  </code></pre>
  
  <p>Output Example : <code>&lt;svg&gt;&lt;polyline points='339,52 339,52 339,52 338,53 338,53 337,54 '/&gt;&lt;/svg&gt;</code></p>
  
  <p>And Code : I just put the generate_svg part of the code.</p>
  
  <pre><code>void generate_svg(char *input, char *output)
  {         
      //INPUT OPERATİONS //
  
  FILE *fp;
  int array_size = 0, i=0, max_lines = 0;  // Line counters
  char c;  // To store a character read from file to check whether newline or not
  char *str_joined = NULL;
  
  // Open the file
  fp = fopen(input, "r");
  
  //Count the number of lines for the array size 
  for (c = getc(fp); c != EOF; c = getc(fp))
      if (c == '\n') 
          array_size = array_size + 1;
  fclose(fp);
  
  
  // read the file into an array of coordinates
  Coord *coord = malloc(array_size * sizeof *coord); //preallocation for performance
  fp = fopen(input, "r");
  while(!feof(fp))
  {
     //check whether input getting correctly             
     if(fscanf(fp, "%d, %d", &amp;coord[i].x, &amp;coord[i].y)==2)      
        i++;           
  }
  fclose(fp);
  
  //OUTPUT OPERATIONS
  max_lines = i;
  SVG *svg = malloc(array_size * sizeof *svg); // allocate memory
  size_t total_length=0, length=0; //total length and length of string
  for(i=0; i&lt;max_lines; i++)
  {
      sprintf(svg[i].xy , "%d,%d ", coord[i].x, coord[i].y);
      total_length += strlen(svg[i].xy); 
      //printf("%s\n", svg[i].xy);
  }
  
  str_joined = (char*)malloc(total_length * sizeof *str_joined); // allocate memory for joined strings
  str_joined[0] = '\0'; // empty string we can append to
  
  for(i=0; i&lt;max_lines; i++)
  {
           strcat(str_joined, svg[i].xy);
           length = strlen(str_joined);
  
           str_joined[length+1] = '\0';           /* followed by terminator */
  
  }
  
  FILE *fp_out;
  fp_out = fopen(output,"w+"); //erase the content and write on it if exists or create the file and write on it
  
  if(fp_out == NULL)
  {
    printf("Error");           
  }
  else
  {
    fprintf(fp_out, "&lt;svg&gt;&lt;polyline points='%s'/&gt;&lt;/svg&gt;" , str_joined);
  
     printf("Operation successful.\n");
  }
  //printf("%s\n", str_joined);
  </code></pre>
  
  <p>}</p>
  
  <p>So any help will be appreciated. Thanks in advance.</p>
  
  <p>//UPDATE</p>
  
  <p>Header: </p>
  
  <pre><code>//definitions
  #define MAX_FILE_NAME 100
  #define OUTPUT_FILE_NAME "svg_output.svg"
  
  void generate_svg(char *input, char *output);
  //storage for coordinates
  typedef struct Coord
  {
      int x;
      int y;
  }Coord;
  
  typedef struct SVG
  {
    char xy[20];        
  
  }SVG;
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/yP1IR.jpg" rel="nofollow">So application crash image :</a></p>