Reading console input in Kotlin

Note that since Kotlin 1.6 readLine()!! should be replaced with readln(). Here are A+B examples in Kotlin reading from stdin: fun main() { val (a, b) = readLine()!!.split(‘ ‘) println(a.toInt() + b.toInt()) } or fun main(vararg args: String) { val (a, b) = readLine()!!.split(‘ ‘).map(String::toInt) println(a + b) } or fun readInts() = readLine()!!.split(‘ ‘).map … Read more

What are the differences between readable and data event of process.stdin stream?

They are two different APIs that allow you to access the same stream of data blocks. The ‘readable’ API was introduced in Node 0.10.0 as part of “Streams 2”, so if you search for that, it should help. The core of the issue is that the ‘readable’ interface allows for much simpler managing and buffering … Read more

How to read from stdin with fgets()?

here a concatenation solution: #include <stdio.h> #include <stdlib.h> #include <string.h> #define BUFFERSIZE 10 int main() { char *text = calloc(1,1), buffer[BUFFERSIZE]; printf(“Enter a message: \n”); while( fgets(buffer, BUFFERSIZE , stdin) ) /* break with ^D or ^Z */ { text = realloc( text, strlen(text)+1+strlen(buffer) ); if( !text ) … /* error handling */ strcat( text, … Read more