1
/* Beginning 2.0 */
#include<stdio.h>
main()
{
    printf(" %d signifies the %c of %f",9,'rise',17.0);
    return 0;
}

Hello people

When I compile this, the compiler giving the following warning:

warning: multi-character character constant [-Wmultichar]|

And the output only prints e instead of rise.

Are multiple characters not allowed in C?

How can I print the whole word (rise)?

Please help me out.

herohuyongtao
  • 49,413
  • 29
  • 133
  • 174
kri
  • 67
  • 1
  • 1
  • 2

2 Answers2

10

Use %s and "" for a character string:

printf(" %d signifies the %s of %f",9,"rise",17.0);
                          ^^          ^    ^

For 'rise', this is valid ISO 9899:1999 C. It compiles without warning under gcc with -Wall, and a “multi-character character constant” warning with -pedantic.

According to the standard (§6.4.4.4.10),

  • The value of an integer character constant containing more than one character (e.g., 'ab'), [...] is implementation-defined.
herohuyongtao
  • 49,413
  • 29
  • 133
  • 174
10

Try: printf(" %d signifies the %s of %f",9,"rise",17.0);.

C distinguishes between a character (which is one character) and a character string (which can contain an arbitrary number of characters). You use single quotes ('') to signify a character literal, but double quotes to signify a character string literal.

Likewise, you specify %c to convert a single character, but %s to convert a string.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111