String with \r in the end
-
\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