1
int main(void)
{
    int a=12,b=3;
    printf("\n a+b = %i\n",a+b);
    printf("\n a-b = %i\n",a-b);
    printf("\n a*b = %i\n",a*b);
    printf("\n a/b = %i\n",a/b);
    printf("\n a%b = %i\n",a%b);//conversion type error 
}

The modulus part is giving the warning as Unknown conversion type character 'b' in format.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Gopal Sharma
  • 755
  • 1
  • 12
  • 25

1 Answers1

6

It is printf giving the warning, scape the modulus character with another modulus:

printf("\n a%%b = %i\n",a%b);

As you may see in the manual: printf(3) there's no b flag character, so when printf find your %b in your string it doesn't know what to do. Since you don't want any formatting in that case, just include the % character in your string, you just need to scape the % character with another % character as in the example above.

Paulo Bu
  • 29,294
  • 6
  • 74
  • 73
  • Yes it's working now, but why this extra %? – Gopal Sharma Mar 22 '14 at 16:48
  • 2
    Added a brief explanation and the reference to the manual page. Those are the semantics for printf :) – Paulo Bu Mar 22 '14 at 16:49
  • 2
    @Gopal In `%%` for the `printf(3)` function, the first `%` acts as an escape character for the second `%`. It tells `printf` that the character following the first `%` is not a "conversion type character", but an actual percent symbol. – Diti Mar 22 '14 at 16:51