One of the most common standard tasks is to implement a "cat program": read all of STDIN and print it to STDOUT. While this is named after the Unix shell utility cat.

Task

  • You should write a full program which reads the contents of the standard input stream and writes them verbatim to the standard output stream.
  • If and only if your language does not support standard input and/or output streams, you may instead take these terms to mean their closest equivalent in your language (e.g. JavaScript's prompt and and alert).
  • The output should contain exactly the input and nothing else.
  • This also applies to newlines.

Solutions

Jump to C, CSharp, JavaScript, PHP Solution.
You can submit your own solution in comment section in same/different programming language. If your solution is better or in different language we'll add here.

C

#include<stdio.h>
int main()  
{
    int i;
    while(i=~getchar())
    putchar(~i);
}

CSharp

using System;

namespace testcs  
{
    class Program
    {
        static void Main(string[] args)
        {
            for (;;System.Console.WriteLine(System.Console.In.ReadLine()));
        }
    }
}

JavaScript

<html>  
<body>  
    <script>
    for(;;alert(prompt()));
    </script>
</body>  
</html>  

PHP

<? fpassthru(STDIN);