Question

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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top