Reading the file contents

We are going to leverage C interoperability to read the contents of a CSV file using the fgets function.

The fgets function reads characters from the file stream and stores them as a C string until (num-1) characters have been read or either a newline or the end-of-the-file (EOF) is reached, whichever happens first. The function stops reading when a newline \n character is encountered, but it is considered a valid character and included in the string copied to str:

    char * fgets (char * str, int num, FILE * stream);

The parameters are as follows:

  • str: Pointer to str where the content read is stored
  • num: Maximum number of characters to be copied into str
  • stream: Pointer to the FILE stream that identifies an input ...

Get Kotlin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.