Logo

Programming-Idioms

History of Idiom 120 > diff from v35 to v36

Edit summary for version 36 by dark:
[C] this IS how you do it in C

Version 35

2019-01-23, 18:53:08

Version 36

2019-03-29, 17:01:59

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];

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