B
When is found a \t, he advances to the next tab stop. And this varies according to the size that is configured in the terminal you are using.For example, in my terminal the size tab stop It's 8, so the exit was like this:Fahr: 0 Celsius:-17
Fahr: 20 Celsius:-6
Fahr: 40 Celsius:4
etc...
What happens is that whenever there is one \t, he advances to the next tab stop, that in my case is every 8 characters. It would be something like that (the ruler below was blatantly copied inspired https://stackoverflow.com/a/13094746 0 8 16 24
|.......|.......|.......|...
Fahr: 0 Celsius:-17
Fahr: 20 Celsius:-6
In the case, 0, 8, 16, etc are the Tab stops (always multiple 8, since the size in my terminal is 8).Then in the first case, the zero occupies position 6, and the \t is in position 7. Then he moves to the next tab stop, which is position 8.In the second case, \t is in position 8, so he advances to the next tab stop, which is position 16.In your case (assuming that the spaces shown are in this same way), it seems that the size tab stop It's 4, so you'd be like this:0 4 8 12 16 20 24
|...|...|...|...|...|...|...
Fahr: 0 Celsius: -17
Fahr: 20 Celsius: -6
Now Tab stops are the multiple positions of 4.In the first case, zero occupies position 6, and \t is in position 7. Then he moves to the next tab stop, which is position 8.And in the second case, the \t is in position 8, so he advances to the next tab stop, which is position 12.A solution would be rather than depend on tab stop, simply set a fixed size for the numbers. For example, switch to:printf("Fahr: %-6d Celsius: %d\n", fahr, celsius);
In the case, - says to align to the left, and 6 indicates the size to be used (and filled with spaces, i.e., both makes the size of tab stop, will always use this size). With this the output will be:Fahr: 0 Celsius: -17
Fahr: 20 Celsius: -6
Fahr: 40 Celsius: 4
Fahr: 60 Celsius: 15
Fahr: 80 Celsius: 26
Fahr: 100 Celsius: 37
Fahr: 120 Celsius: 48
Fahr: 140 Celsius: 60
Fahr: 160 Celsius: 71
Fahr: 180 Celsius: 82
Fahr: 200 Celsius: 93
Fahr: 220 Celsius: 104
Fahr: 240 Celsius: 115
Fahr: 260 Celsius: 126
Fahr: 280 Celsius: 137
Fahr: 300 Celsius: 148
But of course the exact sizes will depend on what you need. For example, if any number has more than 6 digits, it will be dismantled again:Fahr: 999999 Celsius: 555537
Fahr: 1000019 Celsius: 555548
But then you have to adapt the exit to each case. Anyway, the general idea and the explanation are there. You can see in https://en.cppreference.com/w/c/io/fprintf all available options accepted by printf.