I've been trying the last few days to get this code to work but it still wont return the exact numbers. Its always atleast like 10 characters off and it probably is a trivial answer but I cant find the solution. I've initialized the charCount to 0 but still it won't run exactly.
int charcount()
{
int length=1000000;
int charCount=0;
FILE * pFile;
char mychar [1000000];
char openfile [20];
cout<<"\nFile name to open: ";
cin>>openfile;
pFile = fopen (openfile ,"r");
if (pFile == NULL) perror ("Error opening file");
else {
fgets (mychar , 1000000 , pFile);
}
for ( int i = 0; i < length; i++) {
if ('a' <= mychar[i] && mychar[i] <= 'z')
{
charCount=mychar[i];
charCount++;
}
}
puts (mychar);
cout<<" "<<endl;
cout<<"Number of Characters: "<<charCount<<endl;
return 0;
}
}