I have the following example
#include <stdio.h>
#include<conio.h>
void main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
_getch();
}
First off , I don't understand how the printf function works. I have been trying to find tutorials that explain this, but they are too basic.
The way understand this is that there is a cursor which reads every character along the input. For example if we just have the line:
printf("\bsi")
by intuition I would think that it just outputs the string si since there is no previous characters before si, but the output is i. I also want to add that \b takes into account the input of another printf which is weird.
I also think that all those printfs are equivalent to just one printf. Something like:
printf("\nab\bsi\rha");
which makes me think that there is something going on behind the bars that I can't really explain or tell what it is. I think it's something related to some pointer on the input or printf stores the input in a buffer and reads it in a certain way.
Can someone explain how printf works in detail?
....
The question is a bit different because I know it's the same exercise, but I have a different opinion about it and approach it in a different way.