27
2
In the C standard library, header names end with a .h
suffix:
stdio.h
In C++, those header names are available in an alternative form, with a c
prefix instead:
cstdio
Write a function that converts the first form into the second. You can do the conversion in-place, or leave the original string intact and return a new string. Whatever feelds natural in your language of choice.
The code must be compiled/interpreted without errors. Compiler warnings are acceptable.
Here is your baseline C solution. It has 70 characters and generates a warning about strlen
:
void f(char*h){int i=strlen(h);h[--i]=0;while(--i)h[i]=h[i-1];*h='c';}
The shortest solution (measured in number of characters) wins.
Update: If your language of choice does not support functions, whole programs are also acceptable.
Update: As suggested by FUZxxl, here is a complete list of the header files in the C standard library:
assert.h
ctype.h
errno.h
float.h
limits.h
locale.h
math.h
setjmp.h
signal.h
stdarg.h
stddef.h
stdio.h
stdlib.h
string.h
time.h
Specifically, there are no header names with multiple dots in them.
Nice, this takes me back :) – fredoverflow – 2015-02-12T20:24:40.790
Definitely one of the cooler solutions! But the source code isn't really 13 bytes, only the compiled form of it (that I think few of us would want to write in a hex editor). – Per Lundberg – 2015-02-13T19:57:22.757
3Give him his win. Byte = character is a perfectly reasonable interpretation here. – Joshua – 2015-02-13T20:38:41.793
7@PerLundberg I see the source code in this case as being the "how it works" expanded/commented explanation that a lot of people include in their ultra-compact languages. For such a small program it could very well have been hand-written. :) – fluffy – 2015-02-13T21:13:58.817
@fluffy Fair point. And yeah, the number of people that could write the binary code by heart is certainly >0, even though I don't know anyone that geeky myself. ;) – Per Lundberg – 2015-02-14T19:35:46.170