Number of letters in a text file
<p>In this part of program I want read a text file and give length of string in txt file into lenA, but when str1.fa included 10, program output 5, for 6 character shown 3.</p>

<pre><code>   #include &lt;iostream.h&gt;
   #include &lt;stdio.h&gt;
   using namespace std;

   int main(){
int lenA = 0;
FILE * fileA;
char holder;
    char *seqA=NULL;
char *temp;

//open first file
fileA=fopen("d:\\str1.fa", "r");

//check to see if it opened okay
if(fileA == NULL) {
    perror ("Error opening 'str1.fa'\n");
    exit(EXIT_FAILURE);
}

//measure file1 length
while(fgetc(fileA) != EOF) {
    holder = fgetc(fileA);
    lenA++;
    temp=(char*)realloc(seqA,lenA*sizeof(char));
    if (temp!=NULL) {
        seqA=temp;
            seqA[lenA-1]=holder;
    }
    else {
        free (seqA);
        puts ("Error (re)allocating memory");
        exit (1);
    }
}
cout&lt;&lt;"len a: "&lt;&lt;lenA&lt;&lt;endl;
free(seqA);
fclose(fileA);

    system("pause");
return 0;
}
</code></pre>
