Logo

Programming-Idioms

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

Idiom #120 Read integer from stdin

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

(setf n (read-from-string (remove-if-not #'digit-char-p (read-line))))

(setf n (read))
if you don't care if it's explicitly an integer
#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