 <p>Your conversion atof in this code</p> <pre><code>for(k = 0; k &lt; 361; k++) { val = atof(result[k]); cal[k] = val; } </code></pre> <p>is going out of bounds of the array 'result'<br> You only allocate memory to elements in the result array when you have data to put in it </p> <p><code>result[i] = malloc(strlen(value) + 1);</code></p> <p>If less than 361 records were created you are reading from unallocated memory - hence the error.</p> <p>You need to keep a record of how many results you have read in and then use that value to ensure that you remain in range as you process the result array.</p> <p>There is no difference between files based on the file extension.</p>