Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Dart

Idiom #120 Read integer from stdin

Read an integer value from the standard input into the variable n

import 'dart:io';
String? s = stdin.readLineSync();  
int? n = int.tryParse(s ?? "");

n will be null if parsing fails. int.Parse could be used instead if we want to throw an exception when parsing fails.
#include <stdio.h>
int n[15];
fgets(n, 15, stdin);

int n[15]; Int with 15 bytes to use.

Fgets gets user input, and sets n to what it gets

New implementation...
< >
programming-idioms.org