I am relearning C after a long layoff. Going through the book "Learn C on the Mac." One of the sample programs goes through using the backslash controls in the printf function. Here is the code:
#include <stdio.h>
int main (int argc, const char * argv[]) {
printf( "0000000000\r" );
printf( "11111\n" );
printf( "0000\b\b11\n" );
printf( "Here's a backslash...\\...for you.\n" );
printf( "Here's a double quote...\"...for you.\n" );
printf( "Here are a few tabs...\t\t\t\t...for you.\n" );
return 0;
}
and here is the result when built and run in XCode:
0000000000
11111
000011
Here's a backslash...\...for you.
Here's a double quote..."...for you.
Here are a few tabs... ...for you.
Here is the result when run in the Terminal:
1111100000
0011
Here's a backslash...\...for you.
Here's a double quote..."...for you.
Here are a few tabs... ...for you.
It appears that \r and \b are not working in XCode. \r is causing a new line and \b seems to have no effect. I suspect that there is a setting in XCode preferences that is causing this but I can't find it. I have tried compiling with the different compilers offered in XCode but there hasn't been any change. This isn't a big issue as I can't see myself using either \r or \b but I'm curious why they don't work in XCode. Several other folks have reported this on the author's blog but he hasn't been able to reproduce it.
#include <stdio.h>
int main (int argc, const char * argv[]) {
printf( "0000000000\r" );
printf( "11111\n" );
printf( "0000\b\b11\n" );
printf( "Here's a backslash...\\...for you.\n" );
printf( "Here's a double quote...\"...for you.\n" );
printf( "Here are a few tabs...\t\t\t\t...for you.\n" );
return 0;
}
and here is the result when built and run in XCode:
0000000000
11111
000011
Here's a backslash...\...for you.
Here's a double quote..."...for you.
Here are a few tabs... ...for you.
Here is the result when run in the Terminal:
1111100000
0011
Here's a backslash...\...for you.
Here's a double quote..."...for you.
Here are a few tabs... ...for you.
It appears that \r and \b are not working in XCode. \r is causing a new line and \b seems to have no effect. I suspect that there is a setting in XCode preferences that is causing this but I can't find it. I have tried compiling with the different compilers offered in XCode but there hasn't been any change. This isn't a big issue as I can't see myself using either \r or \b but I'm curious why they don't work in XCode. Several other folks have reported this on the author's blog but he hasn't been able to reproduce it.