Вопрос

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.

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top