String with \r in the end
-
char test[20];
strcpy(test, "abcde\r");
strcat(test, "*");
printf("%s\n", test);printf prints:
*bcde
VC++ 2005 debugger shows:
test "abcde*"
And actual string is "abcde\r*". I spent two hours fighting with small file parsing error, when every string ended with \r. As usual, looks quite stupid when the problem is solved.
modified on Monday, September 13, 2010 9:10 AM
-
char test[20];
strcpy(test, "abcde\r");
strcat(test, "*");
printf("%s\n", test);printf prints:
*bcde
VC++ 2005 debugger shows:
test "abcde*"
And actual string is "abcde\r*". I spent two hours fighting with small file parsing error, when every string ended with \r. As usual, looks quite stupid when the problem is solved.
modified on Monday, September 13, 2010 9:10 AM
when fiddling with bytes and characters, I always debug by adding log statements that show the data in hex. I don't want to get fooled by embedded nulls and special characters. And I don't trust Visual Studio debug features much; they tend to "add intelligence" which may work for or against you. And yes, CR (or '\r') can be nasty. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
char test[20];
strcpy(test, "abcde\r");
strcat(test, "*");
printf("%s\n", test);printf prints:
*bcde
VC++ 2005 debugger shows:
test "abcde*"
And actual string is "abcde\r*". I spent two hours fighting with small file parsing error, when every string ended with \r. As usual, looks quite stupid when the problem is solved.
modified on Monday, September 13, 2010 9:10 AM
-
when fiddling with bytes and characters, I always debug by adding log statements that show the data in hex. I don't want to get fooled by embedded nulls and special characters. And I don't trust Visual Studio debug features much; they tend to "add intelligence" which may work for or against you. And yes, CR (or '\r') can be nasty. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Luc Pattyn wrote:
when fiddling with bytes and characters, I always debug by adding log statements that show the data in hex
I prefer to use the memory view windows. It will show the data in hex and ascii. In VS 2005 it is under Debug->Windows->Memory or "Ctrl+Alt+M, 1"
You may be right I may be crazy -- Billy Joel -- Within you lies the power for good - Use it!
-
\r is Carriage return,and it don't equal \n,so you can do this: char test[20]; strcpy(test, "abcde\r\n"); strcat(test, "*"); printf("%s\n", test);
-
char test[20];
strcpy(test, "abcde\r");
strcat(test, "*");
printf("%s\n", test);printf prints:
*bcde
VC++ 2005 debugger shows:
test "abcde*"
And actual string is "abcde\r*". I spent two hours fighting with small file parsing error, when every string ended with \r. As usual, looks quite stupid when the problem is solved.
modified on Monday, September 13, 2010 9:10 AM
-
char test[20];
strcpy(test, "abcde\r");
strcat(test, "*");
printf("%s\n", test);printf prints:
*bcde
VC++ 2005 debugger shows:
test "abcde*"
And actual string is "abcde\r*". I spent two hours fighting with small file parsing error, when every string ended with \r. As usual, looks quite stupid when the problem is solved.
modified on Monday, September 13, 2010 9:10 AM
Have you ever worked with an old teletype or dotmatrix printer? ;) Marc
-
char test[20];
strcpy(test, "abcde\r");
strcat(test, "*");
printf("%s\n", test);printf prints:
*bcde
VC++ 2005 debugger shows:
test "abcde*"
And actual string is "abcde\r*". I spent two hours fighting with small file parsing error, when every string ended with \r. As usual, looks quite stupid when the problem is solved.
modified on Monday, September 13, 2010 9:10 AM
-
char test[20]; strcpy(test, "abcde"); strcat(test, "*"); printf("%s\n", test); now the output is abcde* '\r' means the new line will start at the begin of the same line and the former characters will be covered off
-
\r can be nifty for updating status in place in a console tool; like showing a twirling bar, or updating percentage complete value. You can see it in something like pkzip or robocopy. Some of us are even old enough to have written code like this. :-D
Matt Gerrans
-
It was file scanning algorithm bug, which added \r to every string by mistake. It would be better to have \r\n in this bug, you are right! I my next bug I will try to do this.
modified on Thursday, September 16, 2010 10:40 AM
You plan your bugs in advance? Now that's organised! :laugh: Is there a form you have to fill in before you start coding a bug, or do you just wing it and publicise it later? (I used to have a Bug Request form, produced by the same secretary that issued the "Fire in the building instructions": "In case of fire, do not leave the lift.")
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
You plan your bugs in advance? Now that's organised! :laugh: Is there a form you have to fill in before you start coding a bug, or do you just wing it and publicise it later? (I used to have a Bug Request form, produced by the same secretary that issued the "Fire in the building instructions": "In case of fire, do not leave the lift.")
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Some programmers don't understand what is Wicked Code forum, and explain me how to fix this bug, something like "Hey, just remove \r in the end, and everything will be fine!". I really don't know how to react to these posts, planning my bugs is kind of sarcasm. But generally, this is a good idea, planned bugs are easy to fix. Is Bug Request form available online and free for commercial use?
-
\r can be nifty for updating status in place in a console tool; like showing a twirling bar, or updating percentage complete value. You can see it in something like pkzip or robocopy. Some of us are even old enough to have written code like this. :-D
Matt Gerrans
And what is really cool is when you pipe the output from a console application like that to a text file.... X|
-
And what is really cool is when you pipe the output from a console application like that to a text file.... X|
Not a problem if the program was well written; for example robocopy has the /np option for exactly that purpose.
Matt Gerrans