11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4.6 Output Commands • 181Writing Bytes to a FileThe writebytes command writes one or more individual characters orbytes to a file. You can specify the bytes either as a string or a list ofintegers.The following syntax calls the writebytes command.writebytes( fileIdentifier, bytes )The fileIdentifier is the name or descriptor of the file to which writebytesis writing. The bytes argument specifies the bytes to write. This can beeither a string or a list of integers. If you call writebytes with a filename,and that file is not open, Maple opens it in WRITE mode. If you specifythe bytes as a string, Maple opens the file as a TEXT file; if you specifythe bytes as a list of integers, Maple opens the file as a BINARY file.Example The following example defines a Maple procedure which readsan entire file and copies it to a new file using writebytes.> CopyFile := proc( sourceFile::string, destFile::string )> writebytes(destFile, readbytes(sourceFile, infinity));> end proc:Formatted OutputThe fprintf and printf commands write objects to a file, using a specifiedformat.Call the fprintf and printf commands as follows.fprintf( fileIdentifier, format, expressionSequence )printf( format, expressionSequence )The fileIdentifier is the name or descriptor of the file to which Maple is towrite. A call to printf is equivalent to a call to fprintf with defaultas the fileIdentifier. If you call fprintf with a filename, and that file isnot yet open, Maples opens it in WRITE mode as a TEXT file.The format specifies how Maple is to write the elements of the expressionSequence.This Maple string consists of a sequence of formattingspecifications, possibly separated by other characters. Each format specificationhas the following syntax, where the brackets indicate optionalcomponents.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!