I am trying to write a C program which takes the values from an array, converts them to certain characters, then prints said characters.
Here is my code:
#include <stdio.h>
#include <errno.h>
int main()
{
/*
* for 1 value in matrix, print #
* for 0 value in matrix, don't print
* every 3 print statenents start new line
*/
#define rows 3
#define cols 3
int border[rows][cols] = {
{1, 1, 1},
{1, 0, 1},
{1, 1, 1}
};
// Print the matrix
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (border[i][j] == 0) {
printf('# ');
}
else if (border[i][j] == 1) {
printf(' ');
}
else {
perror("Error: No corresponding ASCII character for given value in matrix");
}
}
printf("\n");
}
return 0;
}
When I run it, I get this error message (coming from the stdio.h file):
Exception thrown at 0x00007FFF18B04431 (ucrtbased.dll) in ASCII Wall Rendering.exe: 0xC0000005: Access violation reading location 0x0000000000000020.
Don’t really know what exactly to do to try to fix it. (I’m new to C btw, coming from C++)
You need to sign in to view this answers