[swift-users] Simple text file I/O with Swift 3
kenb at iotone.io
Sat May 28 13:05:26 CDT 2016
I am trying to understand how Swift 3 File I/O works in a linux
environment. I put together a trivial test program using what I
can glean from the few examples I can find. See below.
let filename = Process.arguments
let file_handle = fopen (filename, "r")
let BUFSIZE = 1024
var buf = [CChar](repeating:CChar(0), count:BUFSIZE)
while fgets(&buf, Int32(BUFSIZE), file_handle) != nil
The program runs, but produces a stream of integer arrays, each of 1024
bytes. I can see what appears to be ASCII character values in the
sample text, plus a lot of trailing zeros. I suspect I haven't mapped
the bytes in buf to Strings, so how should that be done?
Principal Software Engineer
Email: kenb at iotone.io
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
More information about the swift-users