Printf question (newbie)

I want to print in a terminal the "%"character when I put

printf(" %c % ",var);

the % doesn't print

why??

Parents
  • "the % doesn't print

    why??"


    Because '%' flags the start of a conversion specification in the format string. Check your C books and manuals. They'll show you that for printf() to emit a '%', you must use "%%" in the format string, so your example should be:

    printf(" %c %% ",var);

Reply
  • "the % doesn't print

    why??"


    Because '%' flags the start of a conversion specification in the format string. Check your C books and manuals. They'll show you that for printf() to emit a '%', you must use "%%" in the format string, so your example should be:

    printf(" %c %% ",var);

Children
More questions in this forum