Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiler warning when using `%*s` with `printf`

Tags:

c

printf

warnings

When I compile the following:

printf("%*s",lengths[i],row[i]);

I get this warning:

4.0.c:407: warning: field width should have type ‘int’, but argument 2 has type 
‘long  unsigned int’

lengths is declared as: unsigned long *lengths;.

I tried to solve the problem but to no avail. Adding this,

printf("%*lu",(unsigned long)lengths[i],row[i]);

I get no more warnings but the code doesn't work as it should.

Thank you Vera

like image 911
Vera Avatar asked Apr 26 '26 10:04

Vera


1 Answers

Cast it to an int:

printf("%*s", (int) lengths[i], row[i]);
like image 188
Tom Zych Avatar answered Apr 29 '26 00:04

Tom Zych



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!