Copy stdin to stdout: Difference between revisions

no edit summary
(→‎C: Made the code portable. The function "getchar" returns an int; storing its result in a char variable can mean the loop comparison is never true if a char is unsigned on your platform. Also, I modified the formatting slightly.)
Tags: Mobile edit Mobile web edit
No edit summary
Line 361:
The special string "-" indicates reading from stdin.
<syntaxhighlight lang="frink">print[read["-"]]</syntaxhighlight>
 
=={{header|FutureBasic}}==
This code uses FileHandles to interact with standard input and standard output. It continuously reads from standard input and writes to standard output until it reaches the end of input.
<syntaxhighlight lang="futurebasic">
// Create file handles for standard input and output
FileHandleRef stdIn = fn FileHandleWithStandardInput
FileHandleRef stdOut = fn FileHandleWithStandardOutput
 
// Continuously read from standard input…
while (YES)
CFDataRef availableData = fn FileHandleAvailableData( stdIn )
if ( fn DataLength( availableData ) == 0 )
break // End of input
end if
// … and write to standard output
fn FileHandleWriteData( stdOut, availableData, NULL )
wend
</syntaxhighlight>
 
=={{header|Go}}==
729

edits