g | x | w | all
Bytes Lang Time Link
084TIS100250315T031320Zl4m2
035Tcl180506T215858Zsergiol
013Raku230627T184927ZSean
004Thunno 2 j230627T183749ZThe Thon
005Vyxal210602T044757ZUndersla
043Acc!!210602T032326ZDLosc
023Excel formula180507T000613Za stone
041SNOBOL4 CSNOBOL4180514T183037ZGiuseppe
027Stackers180514T182420ZAlex All
006Japt180507T101108ZEtheryte
063Whitespace180507T103244ZKevin Cr
00505AB1E180507T095202ZKevin Cr
005V180506T224023ZEsolangi
019MATLAB151006T042452ZTom Carp
056TI89 Basic150212T213943ZTheNumbe
085TIS Node Type T21 Architecture150628T001022Zundergro
052C# 6150630T051648Zfsacer
039Lua150630T033745ZTrebuche
023brainfuck150213T180255Zundergro
015Perl program150629T110837Zrandomsi
019Julia150629T095108Zmanatwor
010Awk150629T081349Zmanatwor
007K150628T004711Zkirbyfan
034mk150414T115439ZFUZxxl
014GNU sed r150212T200519ZDigital
021><>150216T101959ZSp3000
041C++14150216T100635Zanatolyg
006gema150214T194140ZSteven T
046Go150213T190757ZElenian
048C++ 14150214T144653ZAnmol Si
1514Perl150214T123500Zmalkaroe
nan150212T223112Zcaptncra
016Ruby150213T072710ZKokizzu
007Pyth150212T194602Zisaacg
008Ostrich 0.6.0150213T030642ZDoorknob
033MS QuickBasic or QB64 ~150213T184508ZHSchmale
006CJam150212T200336ZOptimize
031Prelude150213T153209ZMartin E
031F# 39 37150213T094604Zoopbase
020JavaScript ES6150213T110132Zedc65
011Windows Batch file150213T093242ZAlchymis
033R150213T080132ZSven Hoh
038C150213T051035Zfeersum
064C150212T205348ZDigital
015TIBASIC 83/84150212T234038ZTimtech
024Marbelous150212T225522Zes1024
009J150212T202324ZFUZxxl
020Perl —150212T191741Zuser1177
008Dyalog APL150212T202532ZFUZxxl
01380386 machine code150212T202049Zanatolyg
018Bash150212T200115ZDigital
023Haskell —150212T194440Zfredover
016CoffeeScript150212T195015ZTony Ell
058TSQL —150212T194617Zbmarks
025Java 8 —150212T192031Zfredover
019Python150212T192050ZFunctino

TIS-100, 84 bytes

mov 53 acc
d:add 46
mov acc any
mov up acc
sub 46
jnz d
add up
MOV UP ANY
mov up any

Same level as undergroundmonorail, but its byte count is wrong so I save like one line than 1 byte

Tcl, 35 bytes

proc H h {list c[regsub ..$ $h ""]}

Try it online!

Raku, 13 bytes

{'c'~S/..$//}

Try it online!

S/..$// returns the result of chopping off the last two characters of the string, and 'c' ~ prepends a "c" to the front.

Thunno 2 j, 4 bytes

2ẓ'c

Attempt This Online!

Explanation

2ẓ'c  '# Implicit input
2ẓ     # Remove last two characters
  'c  '# Push the character "c"
       # Join the stack
       # Implicit output

Vyxal, 5 bytes

\cpṪṪ

Explanation:

\cpṪṪ   # full program
\c      # c
  p     # prepend using implicit input
   ṪṪ   # remove last two letters

Try it Online!

Acc!!, 43 bytes

Write 99
N
Count i while _/96 {
Write _
N
}

Try it online!

Algorithm

Excel formula, 36 23 bytes

If the input is put in cell A1,

="c"&LEFT(A1,LEN(A1)-2)

Explanation

="c"&LEFT(A1,LEN(A1)-2)
="c"&                     Return the letter 'c' concatenated with...
     LEFT(            )   the first...
             LEN(A1)-2    (the length of input, minus 2 from the '.h') characters...
          A1,             of the input.

SNOBOL4 (CSNOBOL4), 41 bytes

	INPUT ARB . O RPOS(2)
	OUTPUT ='c' O
END

Try it online!

Stackers (27 bytes)

«h ®h 👁h cc ( ~ ~ 🖹

Ungolfed Version

«h "define a table called h
®h "read STDIN to h
👁h "read h to the stack
cc  "add the value for 'c' to the stack
(   "put c on the bottom of the stack
~ ~ "destroy the top two values on the stack
🖹   "print stack bottom two top

Stackers is a programming language I created myself that is meant to be based on stacks, with variables and tables thrown in

Japt, 7 6 bytes

ic ¯-2
ic     # Given the default input, prepend a 'c' at the start
   ¯-2 # and trim off the last two letters.

Try it online!

Whitespace, 63 bytes

[S S S T    T   S S S T T   N
_Push_99_c][T   N
S S _Print_as_character][N
S S N
_Create_Label_LOOP][S S S N
S_Push_0][S N
S _Duplicate][T N
T   S _Read_STDIN_as_character][T   T   T   _Retrieve][S N
S _Duplicate][S S S T   S T T   T   S N
_Push_46_.][T   S S T   _Subtract][N
T   S S N
_If_0_Jump_to_Label_EXIT][T N
S S _Print_as_character][N
S N
N
_Jump_to_Label_LOOP]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Explanation in pseudo-code:

Print "c"
Start LOOP
  Character i = STDIN as character
  if(i == '.')
    EXIT program (with error)
  Print i
  Go to next iteration of LOOP

Program stops with an error: Label_EXIT not found.

05AB1E, 5 bytes

¨¨'cì

Try it online.
Header ε is used to for-each over the input-list to verify all test cases instead of just one.
Footer is to close this for-each, and print the results with new-line delimiter.

Explanation:

¨¨       # Remove the last two characters of the input
    ì    # Prepend:
  'c     #  "c"

V, 5 bytes

éc$xx

Try it online!

Hexdump:

00000000: e963 2478 78                             .c$xx

This is a full program that takes input from STDIN.

Explanation

éc     insert the character 'c'
$      go to the end of the line
xx     delete two characters

This is ic<esc>$xx in pure Vim.

MATLAB, 19

@(c)[99,c(1:end-2)]

Fairly straight forward. Prepends 'c' to the input string less the last two letters. MATLAB automatically converts the 99 (ASCII value) to 'c' when appending to a character string.

TI-89 Basic, 56 bytes

:Def a(a)=Func
:Return "c"+sub(a,1,length(a)-2
:End Func

TIS Node Type T21 Architecture - 85 bytes

This answer is just for fun; the language came into existence after this challenge was written and I therefore cannot win with it. (Not that I was going to.)

Okay, I had a little fun with this one. I probably should just call the language "TIS-100", but why break character? :D

TIS-100 is a game about programming a computer with a totally unique and bizarre architecture. I wrote a custom puzzle for this challenge, which allows me to take input and check output against a known-correct "string". Unfortunately, there's no way to handle strings or characters, so this program simply uses the ASCII value of each character for input and output.

If you'd like to see it in action, you can use this emulator, or just watch me run it in the actual game here. Note that in the video, the final line of the first node is D:MOV UP NIL. After finishing the video, I realized I could golf that down to D:ADD UP. Functionally there's no difference, because the value of ACC is immediately overwritten anyway.

This is the string I used for my byte count:

MOV 99 ANY
MOV -46 ACC
ADD UP
JEZ D
ADD ACC ANY
JRO -5
D:ADD UP
MOV UP ANY
MOV UP ANY

That's the text of each non-empty node, seperated by newlines (effectively adding 1 byte for each node used beyond the first, mirroring our rule about code in multiple files).

C# 6, 52 bytes

class P{string C(string f)=>"c"+f.Replace(".h","");}

C# <6, 58 bytes

class P{string C(string f){return"c"+f.Replace(".h","");}}

Lua, 39 bytes

function f(n)return "c"..n:sub(1,-3)end

brainfuck - 25 23 bytes

,[>,]<-----.<,<[<]>[.>]

If your language of choice does not support functions, whole programs are also acceptable.

This is a whole program that takes input from STDIN.

,[>,]      get all bytes of input
<-----.    subtract 5 from last byte (always "h"; "h" minus 5 = "c") and print result
<,         set second last byte to 0 by abusing comma
<[<]>      go to first byte
[.>]       print byte and move right until hitting 0

Perl (program) 15

s/(.*)\.h/c\1/

It converts filenames supplied on std input, and needs to be run with the p flag, so that's one more character I believe. Eg

echo stdio.h | perl -p header.pl

output:

cstdio

Note to sticklers: I just spotted that this may be invalid because challenge implies that programs are only acceptable if the language doesn't support functions. However, I'm not going to throw it all away at this stage! Ah well.

Update: Augh! And I hadn't spotted page 2 of the answers either. Please refer to @malkaroee's effectively identical answer posted 4 months ago. ... Hang on, who resurrected this thread?

Julia: 19 characters

f(s)="c"*s[1:end-2]

Sample run:

julia> f(s)="c"*s[1:end-2]
f (generic function with 1 method)

julia> print(f("stdio.h"))
cstdio

Awk: 10 characters

$0="c"$1

Sample run:

bash-4.3$ awk -F. '$0="c"$1' <<< 'stdio.h'
cstdio

K, 7 bytes

"c",-2_

Pretty simple. Just drops 2 chars off the end and prepends a c.

Also, despite how it looks, this is actually a function:

f:"c",-2_
f"stdio.h"

mk, 34 characters

mk(1) is the Plan 9 replacement for make. Just for fun, this mkfile converts C header names into C++ header names:

c%:Q:
    :

%.h:Q: c%
    echo $prereq

There is a single tab before : and echo. Use like this:

% mk stdio.h
cstdio

GNU sed -r, 14

sed doesn't really have any concept of functions, so here is a complete sed program instead:

s/(.*)../c\1/

Output

$ sed -r 's/(.*)../c\1/' <<< stdio.h
cstdio
$ 

The -r has been included in the score as one extra character.

><>, 22 21 bytes

Since full programs are now allowed...

i:0(?v
~}-5~/r
o;!?l<

Explanation

i:0(?v      Keep reading input until EOF
~}-5~/r     Pop the -1 from EOF, turn 'h' -> 'c' with 5- and shift to back, pop '.', reverse stack
o;!?l<      Keep outputting until the stack is empty

C++14, 41 characters

[](auto&s){s="c"+s.substr(0,s.size()-2);}

Inspired by this other answer. I made it a separate answer because here I use a feature that is new in c++14, generic lambda.

See it in action here.

gema, 6

*.h=c*

(Gema is an obscure macro language.)

Go, 47,46

func h(s string)string{return"c"+s[:len(s)-2]}

I know I'm not winning anything with this, but I thought I might as well go for it. No pun intended

C++ 14, 48

[](string s){return "c"+s.substr(0,s.size()-2);}

Perl, 15 (14 + -p)

s/(.*)\.h/c$1/

piet (9x11 = 99 8X11=88)

v2

another try (2x37 = 74)

enter image description here

Hard to make it much smaller since it needs to generate a 99 ('c') and a 46('.'), and that takes space in piet.

Ruby: 16 characters

->x{?c+x[0..-3]}

Or, more correct solution as suggested by @mbuettner

->x{?c+x[/\w+/]}

You can call it like this:

->x{?c+x[/\w+/]}.call 'stdio.h'
# cstdio

Pyth, 7 characters

L+\cPPb

Explanation:

L         def y(b):return
 +\c                      "c" +
    PPb                         b[:-1][:-1]

Try this:

L+\cPPb
y"stdio.h

on the online Pyth Compiler/Executor


If full programs were allowed:

Pyth, 6 characters

+\cPPQ

Ostrich 0.6.0, 8 characters

););"c\+

) is the "right uncons" operator. When applied to a string, it turns, for example, `foo` into `fo` `o`. ; is used to pop the extra character off, and this is done again.

Then, "c is pushed. This is simply a shorthand for `c`.

\+ swaps the top two stack elements and concatenates them.

MS QuickBasic or QB64 ~ 33 bytes

A$=left$(A$,len(A$)-2)
A$="c"+A$

A$ is the name of the file

CJam, 6 bytes

'clW(<

This is a full program which reads the string via STDIN

Explanation:

'c               "Put character c on stack";
  l              "Read a line from STDIN";
   W             "W is a predefined variable with value -1";
    (            "Decrease the value by 1";
     <           "Remove last 2 characters from the string on stack, the input argument";

Try it online here

Prelude, 31 characters

Since full program submissions are apparently acceptable, here is a program that reads the C-style header from STDIN and prints the C++-style header to STDOUT:

99+9+(?)###(#
9(1-)       ^)(!)

This requires a standard-compliant interpreter which prints output as character codes. If you're using the Python interpreter you'll need to set NUMERIC_OUTPUT = False.

It also requires that there's no trailing newline on STDIN.

Explanation

In Prelude all lines are executed in parallel, one column at a time. Each line has its own stack, initialised to an infinite amount of 0s.

99+9+
9(1-)

This is the shortest I could come up with to get a 99 onto the top stack (the character code of c). First I add up 18 on the top stack and push a 9 onto the bottom stack. The bottom then counts down to 0 in a loop, while the top stack adds more 9s up. This adds up to 99 on the top stack, and the bottom stack is left with 0s again. Note that all of +9+ is part of the loop, so there are actually two addition operations per iteration, but that's not an issue, thanks to the infinite supply of 0s underneath.

Now (?) reads STDIN, one character at a time and pushes onto the top stack. The loop terminates at the end of the input, when ? pushes a zero. ### gets rid of that zero, the h and the .. Now the next loop pops numbers from the top stack while copying them to the bottom stack. This essentially reverses the stack. Note that the opening and closing parentheses are on different lines - this is not an issue, because the vertical position of the ) is irrelevant in Prelude, but it saves me a byte on the first line.

Lastly, (!) prints all the characters until the stack is empty.

F# - 39 37 31

31 - Because typeinference in F# rocks!

fun s->("c"+s).Replace(".h","")

37

fun(s:string)->"c"+s.Replace(".h","")

39

fun(s:string)->"c"+s.Remove(s.Length-2)

JavaScript (ES6) 20

Can't believe ES6 was still missing

s=>'c'+s.slice(0,-2)

Windows Batch file 11

@echo c%~n1

The first parameter passed in is %1. The ~n modifier returns just the filename without extension.

If it's acceptable to echo the expanded command to the screen as well, then the initial @ could be removed.

R, 33

function(x)sub("(.+)..","c\\1",x)

This function uses regular expressions.

Example usage:

> (function(x)sub("(.+)..","c\\1",x))("stdio.h")
[1] "cstdio"

C, 38

See on Ideone

f(s,o){snprintf(o,strlen(s),"c%s",s);}

s is a pointer to the input string, and o is where the output should be written to.

I found a way to abuse snprintf. The output string conveniently happens to be one character shorter than the input, and the maximum length of the string written by snprintf is 1 less than the n argument, so it cuts off the .h. Note: this technique will not work with Microsoft's implementation because it does the wrong thing and fails to null-terminate the string.

C, 64

Mildly shorter than the c reference:

f(char*h){char*d=strstr(h,".");memmove(h+1,h,d++-h);*d=0;*h=99;}

Probably more golfing to be done with this.


C, 48 (libc hack)

f(char*h){strcpy(h+1,h);*strstr(h,".")=0;*h=99;}

The strcpy manpage explicitly states "The strings may not overlap". However I found that the libc I am using appears to be coded safely to handle this correctly all the same. This is GNU C Library (Ubuntu EGLIBC 2.19-0ubuntu6.4) on Ubuntu 14.04.

TI-BASIC 83/84, 15

"c"+sub(Ans,1,length(Ans)-2

Marbelous, 24

@063
-Z//
3W<C+Z
]]!!
@0

Takes input through STDIN, outputs to STDOUT.

This works by checking each byte with . (0x46). As 0x46 cannot fit inside a single base-36 digit, we subtract 35 (Z) before comparing, and add it back before outputting.

Each marble is duplicated by 3W (three-way duplicator, but the left side is discarded off the side of the board). The marble sent downwards fetches the next byte from STDIN. The marble to the right is checked to ., then either outputted, or sent to !!, which terminates the program.

The program starts by passing c (0x63) through, which will be output to STDOUT.

Try it online here. Libraries must be enabled, cylindrical boards must be disabled.

J (9 characters)

'c',_2}.]

Perl — 20 characters

sub{c.pop=~s/..$//r}

Note how c is a bareword and as such this requires a lack of use strict. This must be used as an expression, not a statement.

Dyalog APL (8 characters)

'c',¯2↓⊢

This solution is exactly the same as the J solution I submitted but uses one character less due to being one character less than }..

80386 machine code, 13 bytes

Hexdump of the code:

b0 63 86 01 41 3c 2e 75 f9 c6 01 00 c3

Source code (can be compiled by Visual Studio):

__declspec(naked) void __fastcall conv(char s[])
{
    _asm {
        mov al, 'c';            // b0 63
    myloop:
        xchg al, [ecx];         // 86 01
        inc ecx;                // 41
        cmp al, '.';            // 3c 2e
        jne myloop;             // 75 f9
        mov byte ptr [ecx], 0;  // c6 01 00
        ret;                    // c3
    }
}

It converts the string in-place. The code is so simple, it doesn't need to save and restore registers (using only al and ecx, which the fastcall convention allows to clobber).

Bash, 18

f()(echo c${1%.*})

Output:

$ f stdio.h
cstdio
$ 

Haskell — 23 characters

('c':).takeWhile(/='.')

Haskell — 16 characters, as suggested by nimi

('c':).init.init

CoffeeScript - 16

(x)->"c"+x[..-3]

T-SQL — 58 characters

CREATE PROC Q(@ VARCHAR(MAX))AS
SELECT'c'+LEFT(@,LEN(@)-2)

Run as EXEC Q (your string here)

Java 8 — 25 characters

h->"c"+h.replace(".h","")

Python: 19 characters

lambda s:'c'+s[:-2]