Search code examples
cprintfformat-specifiersformat-string

Format specifier in printf() asks for an int when should be char


I'm using Pelles C ide and I'm learning C, I thought I learned that %c was the format specifier for char in printf(), but it thinks I'm trying to use int? How can I correct this problem.

Here is the code:

#include <stdio.h>

int main(void)
{
char z[] = "       *\n";
char m[] = "      *\n";
char k[] = "     *\n";
char o[] = "*   *\n";
char l[] = " * *\n";
char e[] = "  * ";



printf(" %c", z);
printf(" %c", m);
printf(" %c", k);
printf(" %c", o);
printf(" %c", l);
printf(" %c", e);



return 0;

}

Here is the errors: enter image description here


Solution

  • You should be using a string specifier to output character strings.

    printf("%s", z);