December 2017
Intermediate to advanced
260 pages
7h 34m
English
Finally, after pooling all the bits and pieces of the code explained in the previous sections, here is the complete code:
import kotlinx.cinterop.* import platform.posix.* /** * The starting point */ fun main(args: Array<String>) { // Get command line input if (args.size != 2) { println("Usage: csv_filename column_number") return } val fileName = args[0] val columnNumber = args[1].toInt() // Open the file val file = fopen(fileName, "r") if (file == null) { perror("Failed to open the file named $fileName") return } val result = mutableMapOf<String, Int>() try { memScoped { // Memory allocation for buffer val bufferLength = 64 * 1024 val buffer = allocArray<ByteVar>(bufferLength) while (true) { // Get line val nextLine = fgets(buffer ...
Read now
Unlock full access