fast_integer_input.cpp File Reference

Read integers from stdin continuously as they are entered without waiting for the `\n` character. More...

`#include <iostream>`
Include dependency graph for fast_integer_input.cpp:

## Functions

void | fastinput (int *number)
int | main ()

## Detailed Description

Read integers from stdin continuously as they are entered without waiting for the `\n` character.

## Function Documentation

## fastinput()

void fastinput | ( | int * | number | ) |

Function to read the number from stdin. The function reads input until a non numeric character is entered.

{
// variable to indicate sign of input integer
bool negative = false;
register int c;
*number = 0;
// extract current character from buffer
c = std::getchar();
if (c == '-') {
// number is negative
negative = true;
// extract the next character from the buffer
c = std::getchar();
}
// Keep on extracting characters if they are integers
// i.e ASCII Value lies from '0'(48) to '9' (57)
for (; (c > 47 && c < 58); c = std::getchar())
*number = *number * 10 + c - 48;
// if scanned input has a negative sign, negate the
// value of the input number
if (negative)
*(number) *= -1;
}
std::getchar
T getchar(T... args)
Here is the call graph for this function:

## main()

int main | ( | void |  | ) |

Main function

{
int number;
fastinput(&number);
std::cout << number << std::endl;
return 0;
}
std::cout
std::endl
T endl(T... args)
fastinput
void fastinput(int *number)
Definition: fast_integer_input.cpp:11
Here is the call graph for this function: