Friday, 15 April 2011

Escaping control characters (programming)

Basically, in C, there is a control character "\" which is a slash. \n is one character, \r is another, \t is a tab, etc. Now, what do you think the control character itself should be? Well typically it is "\\". But this involves some silly search-and-replacing to change "\\" to "\".

My solution is to escape the control character itself. So you say "\e" which is replaced with a "\". Now you can process the string without first replacing all the slashes. Much better - and it doesn't even take up any more space.

Update on American hanging-up-without-saying-goodbye

I figured it out when watching a film. Basically, there is a click on the line when someone hangs up. That's how they know someone has gone without having to say goodbye.