In addition to watch Richard wrote,
scanf
can be a problematic function. You are already calling
fgets
and it is better function to use for acquiring input. You can convert strings to numeric values with
atoi[
^] and
atof[
^]. You can also easily adapt your code to read input from a file instead of
stdin
if you want to and that can make your testing go much faster and easier. You can do that be first calling
fopen[
^] to open the file. This documentation for
fgets[
^] has a snippet of code that opens a text file and reads lines of text from it. If you add the
for
loop you already have and its code then you are ready to go.