Check that your file is actually being opened, otherwise printf() will try to print out random memory which may go beyond the bounds of what you have actually allocated and cause an error.
input = fopen("test.txt", "rt");
if (!input)
{
perror("Failed to open file");
exit(1);
}
You may also want to check that a == 1
, i.e. that the fscanf()
also succeeds.