Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c language: printf help

Tags:

c

printf

here is my coding which gives me the error 'warning: unknown conversion type character 0x20 in format'

int subtotal;
long long a,b,c,d,e,f,g,h,i,j,k,l,m;
subtotal = (1*(a+c+e+g+i+k))+(3*(b+d+f+h+j+l));
printf(" = %d % 10 = %d; (10 - %d) % 10 = %lld\n", subtotal,subtotal%10,subtotal%10,m);

any idea why this is wrong?

like image 853
dydx Avatar asked Jul 03 '26 06:07

dydx


2 Answers

Ignoring the fact you have a bunch of uninitialised variables, the % character is a special one in printf format strings - if you want a literal '%', you need '%%'.

printf(" = %d %% 10 = %d; (10 - %d) %% 10 = %lld\n", subtotal,subtotal%10,subtotal%10,m);

In printf you need a escape character to print % on the console you need to use %%

like image 25
Naveen Avatar answered Jul 08 '26 23:07

Naveen