Two things I see. First, you’re mixing chars with ints in the matrix array. Second, you’re printing the elements of matrix out to a file using the “%s” format. “%s” expects a null-terminated string where as you are passing chars and ints. This will cause the printf to try and access memory that is out-of-bounds, thus the fault.