My code works for the printing of hashes but it doesn’t pass the check because of the additional space character(” “). I got the error:
“expected “”#””, not “” #”” are you printing an additional character at the beginning of each line?”
How do I make it not print the space but still work as it should to avoid this error?
Every other thing works fine.
I’m getting the desired output, but the code checker complains about the printf(” “) and assumes I’m printing another character.
Here is my code:
#include <cs50.h>
#include <stdio.h>
void print_row(int space, int length);
int main(void){
int height;
do{
height = get_int("Height: ");
}
while(height <= 0);
for(int i = 1; i <= height; i++){
int space = height - i;
int length = i;
print_row(space, length);
}
}
void print_row(int space, int length){
for(int i = 0; i < space; i++){
printf(" ");
}
for(int i = 0; i < length; i++){
printf("#");
}
printf("n");
}
For a height of 3, the result should be:
#
##
###
For a height of 4:
#
##
###
####
For a height of 5:
#
##
###
####
#####
Okoro Hannah Ozioma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
15