This is my code:
int main(void)
{
int i, j, k, n;
char userLatter, space;
printf("please enter an uppercase letter:\n");
scanf("%c", &userLatter);
n = 9;
for (i = 0; i < 5; i++)
{
space = ' ';
for (j = 5; j > i; j--)
{
++space;
}
for (k = 0; k <= i ; k += 1)
{
printf("%c%c%c", space, userLatter, space);
}
printf("\n");
}
}
Can you please tell me what I should do so I can print the space character?
Thanks!
You keep turning the space into something else with the line:
What did you expect that to do? Are you trying to make it a string of multiple spaces
You can left-pad your character by using a
printfformat specifier. Try this:That would output 3 spaces and the letter A:
And if you simply want to put a space in, don’t forget you can just put a space in the format string. As in the famous:
Note there is a space in there.