Logo

Programming-Idioms

History of Idiom 120 > diff from v4 to v5

Edit summary for version 5 by :
New C implementation by user [Roboticus]

Version 4

2016-02-12, 11:36:00

Version 5

2016-02-12, 11:48:57

Idiom #120 Read integer from stdin

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

Idiom #120 Read integer from stdin

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

Imports
// Hmmm ... angle brackets don't show up!
stdio.h
stdlib.h
Code
char inbuff[1000];

int main(int, char **) {
   int n;
   if (!fgets(inbuff, sizeof(inbuff), stdin))
      fabort("Can't read from input");
   n = atoi(inbuff);
   printf("You entered %d\n", n);
}