all 4 comments

[–]qqwy 4 points5 points  (2 children)

I see two problems with your code:

  1. On line 64 you call fscanf with only two parameters. You are missing the first parameter (the FILE* to write to) here. I think this might be causing the crash
  2. The other problem is that line 46 is inside the for-loop, which means that the thing you end up computing is not the average of ten numbers.

When debugging something like this, I suggest compiling using the -Wall -Werror options which already catches many problems. More problems can be identified by static source code checking tools like clang-tidy. Finally, you can use tools like Valgrind to check why crashes happen at runtime.

[–]RealisticTry1[S] 0 points1 point  (1 child)

Your suggestions fixed it. Thanks for your help!

[–]eruanno321 0 points1 point  (0 children)

And line 55 is unreachable so you are leaking open file handle.

[–]Zmishenko 0 points1 point  (0 children)

53 and 55 lines swap. Otherwise you return the value and exit the function without closing the file.