Code::Blocks Forums
User forums => Using Code::Blocks => Topic started by: jimshen on March 06, 2006, 12:57:42 pm
-
I use CB in windows and the compiler is gcc. When I build and run the program below, I found the result is strange. Can anyone give me an explain?
#include <stdio.h>
int main()
{
int a=5,b=6,c=7;
printf("%d\n%d %d\n %d %d\t\b%d\n",a,b,c,a,b,c);
printf("%d %d\t\b%d\n",a,b,c);
return 0;
}
The result is:
5
6 7
75 6
5 67
I tried DevC++ which use MinGW as compiler and got same result. It seems that is the problem of MinGW.
The result should be (When use Turbo C in DOS or gcc in Linux)
5
6 7
5 6 7
5 6 7
-
Hmmm, what about the \b?
Best wishes,
Michael
-
Hmmm, what about the \b?
Best wishes,
Michael
\b and \t.
-
\b is backspace escape character
Ah yes. Thanks :). I have found in google too (was not so easy though). I never use it anyway.
AFAIK, the output of the second printf is correct. You do a \t and then a \b.
Best wishes,
Michael
-
Ah yes. Thanks :). I have found in google too (was not so easy though). I never use it anyway.
AFAIK, the output of the second printf is correct. You do a \t and then a \b.
Best wishes,
Michael
The result is not same as the result in linux. Please see the first message I modified.
-
The result is not same as the result in linux. Please see the first message I modified.
Yes, I know. I have read the modified version already and tried myself in ubuntu :). I have done some tests, both in Window and in Linux. When I only use \b, the behaviour seems to be the same. But when I use \t\b then the result is different.
Best wishes,
Michael
-
But when I use \t\b then the result is different.
Best wishes,
Michael
That's the problem trouble me.
-
Don't blame the compiler, it does exactly what you tell it to. If you do a hexdump of the executable, you will see that the text location in question reads 25 64 09 08 25 64. It does exactly what you asked for.
It is the MSVCRT which does not handle it correctly. Obviously, Microsoft does not expect anyone to mix tabs and backspaces (I could not imagine a good reason to do so either).
-
Don't blame the compiler, it does exactly what you tell it to. If you do a hexdump of the executable, you will see that the text location in question reads 25 64 09 08 25 64. It does exactly what you asked for.
It is the MSVCRT which does not handle it correctly. Obviously, Microsoft does not expect anyone to mix tabs and backspaces (I could not imagine a good reason to do so either).
Thank you very much. I build the program in Visual c++ and got the same result. It seems that is the problem of MSVCRT.
The code is in a book I'm reading now.