Reading 16 bit binary numbers from file
This is supposed to read a series of 16 bit binary numbers as short ints in the array memory. However, it only appears to be reading the first number, and I can't figure why.
Code:
short int memory[256];
void readFile(){
//read input file into int memory[]
FILE *ifp;
ifp = fopen("proj1a.dat", "r"); //input file
//validates file exists
if (ifp == NULL)
{
perror("proj1a.dat");
exit(0);
}
char str[16];//current line from file
int i = 0; //index of memory
while(fgets(str, 17, ifp)){
memory[i] = (short)(strtol(str, NULL, 2));
printf("%d\n", memory[i]);//DEBUG
i++;
}
}