I've noticed something odd. Your script has ".tst" for the extension instead of ".txt". This would cause the opening of the file to fail.
Looking at your "10001.txt" file in a hex editor, you may want to try something like this (untested, just written):
This is a poor method for doing so as I know there's a much better way, but at least it works.Code:#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *inFile; // a file handle
char current = 0; // initialize the variable
unsigned int total = 0; // the total value
char done = 0; // a flag for finishing
inFile = fopen("10001.txt"); // open the file
if (inFile == 0) // file not found
{
return 0; // terminate the function
}
while (done == 0) // while not done
{
fread(¤t, 1, 1, inFile); // read a single byte
if ((current == 0) || (current = 10)) // null character or \n indicator
{
done = 1; // finished as this is the end
break; // terminate the loop
}
else
{
current -= 48; // adjusts for ASCII position value ("5" is 0x35 or 53, take 48 from that and you get 5)
printf("Value read is %d.\n", current); // shows the value read
total += (int)current; // typecasting may not be needed
}
}
printf("\nThe total is %d.", total);
return 0; // terminate the function as this is the end of it
}