How do I store continuously read in input from the standard input in C? Similar to while (cin >> x)
in C++?
Say I want to store a set of integers into an array/vector with no predefined size. In C++, I can do:
vector<int> vec;
while (cin >> x) {
vec.push_back(x);
}
I haven't found anything online something similar to while (cin >> x)
.
The closest I've found for something similar to while (cin >> x)
is:
int x;
while(scanf("%d", &x) == 1) {
// do stuffs
}
But what this does is continually read through every input, including using the Enter
key in the terminal. So it doesn't stop reading input from the terminal.