I created a simple C program that creates a square according to the users input 4 = 4x4, 5 = 5x5 etc.
My program was not compiling correctly like it is below, and after a while I was able to fix it by removing indentation from the second printf.
Is this normal? or is this just my IDE? I'm very new to C but in general I've never seen indentation affect code functionality, so I just wanted to understand a bit more about that.
Thanks!
int main(void)
{
int height;
do
{
height = get_int("Height: ");
}
while (height>9 || height<1);
for (int i = 0; i < height; i++)
{
for (int j = 0; j < height; j++)
printf ("#");
printf ("\n");
}
}
Error:
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow mario.c -lcrypt -lcs50 -lm -o mario
mario.c:24:6: error: misleading indentation; statement is not part of the previous 'for' [-Werror,-Wmisleading-indentation]
printf ("\n");
^
mario.c:21:4: note: previous statement is here
for (int j = 0; j : mario] Error 1
