I’m learning C after having learned Java (among other languages), and I’m somewhat confused about how to handle this simple problem. I need to write a program that will take input in the form of one line. For example, 5 2 75 43 68 (only ints), and I need to return the number of ints, their sum, and the number of positive and negative numbers.
The problem is that the number of inputs is, obviously, variable–there may be one int or seven, but all will be on one line. I’m not sure how to use C to handle the variable number of inputs. Can someone point me in the right direction?
TO handle variable number of inputs, you need to loop and scanf until you press (Ctrl+D)
Here is an example:
Note: When you press Ctrl+D, scanf returns -1, and hence the process of taking inputs terminates!
Cheers!