We read each line of the file by continuously iterating the file stream until we reach the end of the stream with the help of the fgets function, and break the loop if we hit null, which indicates the end of the stream.
We need to find the unique entries from the specified column (column_number from the command line arguments) and increment the occurrence by checking if it already exists in the ;map with the key, that is, String and value, that is, Int, as shown in the following code snippet:
// Map val result = mutableMapOf<String, Int>() while (true) { // Get line val nextLine = fgets(buffer, bufferLength, file)?.toKString() ?: break // Split line val records = nextLine.split(",") val key = records[columnNumber] ...