How to pass an "int" value into any bits of a "char" array? [closed]
int x = 10;
char denemem[13]="| |";
How can I get the output shown below by writing a code in C programming language? or, more precisely, how can I pass int into the any place (any bits) of a char array I want?
| 10 |
Thank you for all of your help and efforts in advance!
Assuming you want a fixed width, printf can do that directly, as long as you want left or right justified:
printf("|%10d|", x); // right justified
printf("|%-10d|", x); // left justified
Unfortunately, if you want the number centered in a field, that is much harder to do. You need to figure out how wide the number is and then pad:
int width = snprintf(0, 0, "%d", x);
if (width <= 10) {
width += (10-width)/2;
printf("|%*d%*s|", width, x, 10-width, "");
} else {
// number is too wide for the field -- do something else