Is my syntax incorrect? Did I make an error somewhere?
These are the error messages I received. I have tried fixing all these errors but I have hit a wall and don't know what to do.
~/workspace/pset1 $ make mario
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wshadow mario.c -lcs50 -lm -o mario
mario.c:27:15: error: incompatible pointer to integer conversion assigning to 'char' from 'char [2]' [-Werror,-Wint-conversion]
blank = "s";
^ ~~~
mario.c:29:14: error: incompatible pointer to integer conversion assigning to 'char' from 'char [2]' [-Werror,-Wint-conversion]
hash = "#";
^ ~~~
mario.c:30:16: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *' [-Werror,-Wint-conversion]
printf(blank*(h-(i + 1)));
^~~~~~~~~~~~~~~~~
/usr/include/stdio.h:362:43: note: passing argument to parameter '__format' here
extern int printf (const char *__restrict __format, ...);
^
mario.c:30:16: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
printf(blank*(h-(i + 1)));
^~~~~~~~~~~~~~~~~
mario.c:31:40: error: adding 'int' to a string does not append to the string [-Werror,-Wstring-plus-int]
printf(hash*((h+1)-(h-(i + 1)))+"\n");
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
mario.c:31:40: note: use array indexing to silence this warning
mario.c:31:16: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
printf(hash*((h+1)-(h-(i + 1)))+"\n");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 errors generated.
make: *** [mario] Error 1
Source
#include <stdio.h>
#include <cs50.h>
int main()
{
int h;
// asking the user to pick the height of the half pyramid
do
{
printf("Pick a number from 1-23: \n");
h = GetInt();
}
while (h > 23);
// if the number is 5 the half pyramid should look like this
// ----##
// ---###
// --####
// -#####
// ######
// like at the end of super mario
int i;
for (i = 0; i < h; i++)
{
char blank;
blank = "s";
char hash;
hash = "#";
printf(blank * (h-(i + 1)));
printf(hash * ((h+1)-(h-(i + 1)))+"\n");
}
// I wanted to test my code with s and #
// because I don't know how to print blank spaces in C
}