Logo

Programming-Idioms

History of Idiom 120 > diff from v31 to v32

Edit summary for version 32 by garu:
[C] None of the other languages had main function stuff.

Version 31

2018-06-24, 08:10:24

Version 32

2018-11-23, 05:41:45

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
#include <stdio.h>
#include <stdlib.h>
Imports
#include <stdio.h>
#include <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);
}
Code
char inbuff[1000];

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