Stream I/O

This page is under construction. Please come back later.
#!/usr/bin/env swift;
/******************************************************************************
* This program simply copies an input stream to the console character by
* character like the Unix 'cat' program.
*
* Copyright © 2020 Richard Lesh. All rights reserved.
*****************************************************************************/
import Foundation
import Utils
func main() -> Void {
var c:Int?
c = Utils.getchar()
while c != nil {
print(Utils.chr(c!), terminator: "")
c = Utils.getchar()
}
exit(EXIT_SUCCESS)
}
main()
Output
$ swiftc StreamIO1.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$ swiftc StreamIO1.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
#!/usr/bin/env swift;
/******************************************************************************
* This program simply copies an input stream to the console line by line.
*
* Copyright © 2020 Richard Lesh. All rights reserved.
*****************************************************************************/
import Foundation
func main() -> Void {
var line:String?
line = (readLine(strippingNewline: true))
while line != nil {
print(line!)
line = (readLine(strippingNewline: true))
}
exit(EXIT_SUCCESS)
}
main()
Output
$ swiftc StreamIO2.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$ swiftc StreamIO2.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
#!/usr/bin/env swift;
/******************************************************************************
* This program reads bytes from STDIN and prints them in decimal format.
*
* Copyright © 2020 Richard Lesh. All rights reserved.
*****************************************************************************/
import Foundation
import Utils
func main() -> Void {
var c:UInt8?
var count:Int = 0
c = Utils.getbyte(FileHandle.standardInput)
while c != nil {
print(String(c!) + " ", terminator: "")
count += 1
if count % 20 == 0 {
print()
}
c = Utils.getbyte(FileHandle.standardInput)
}
if count % 20 != 0 {
print()
}
exit(EXIT_SUCCESS)
}
main()
Output
$ swiftc StreamIO3.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$ swiftc StreamIO3.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Questions
- {{Who's on first?}}
- {{Who's on second?}}
- {{Who's on third?}}
Projects
More ★'s indicate higher difficulty level.
- Alphabetic Only Filter
- Average Filter
- Caesar Cipher
- Caesar Cipher (Modified)
- Frequency Table (Bytes)
- Frequency Table (Characters)
- Head and Tail
- Hexadecimal Filter
- Hexadecimal Filter with Byte Count
- Hexadecimal Filter (Unicode)
- Histogram
- Line Number Filter
- Lowercase Filter
- Median Filter
- Punchcard Filter
- Random Bytes
- Random Characters
- Simple 8-Bit Checksum
- Simple 32-Bit Checksum
- Standard Deviation
- Total Filter (Floating Point)
- Total Filter (Integer)
- Uppercase Filter
- Vigenère Cipher
- XML Encoding Filter
References
- [[Swift Community]]
- [[Swift Language Guide]]
- [[Swift Language Reference]]
- [[Swift Programming Language]], Apple Inc.
- [[Swift Doc]]
- [[We Heart Swift]]
- [[Swift Cookbook]]
- [[Swift Playground]]
- [[Swift at TutorialsPoint]]
- [[Hacking with Swift]]
Pure Programmer


