I’m writing a program to access a bin packing algorithm function from a library, I haven’t done much with it since college so my C is a bit rusty. The function I’m calling requires I pass in 3 different integer arrays. I’ll be calling this from the command line. Should I use argv? Or STDIN? The input arrays could potentially be 50 to 100 elements each. Either way I suppose I will have to write something to parse the strings and get them into arrays, is there an easy way to do that?
Share
For big arrays, I’d rather use standard input, as there are usually operating system limits to how many arguments you can have.
You will also need some kind of input format. Let’s say the first number
nis the number of elements in the first array, followed by the element values, and so on. Then I’d do something like:You get the general idea. You’d either have to implement
read_numberyourself or find examples on the net on how to do it. You will need to discern individual numbers somehow, e.g. by parsing each digit up to the next white space character. Then you can separate each digit on stdin by space characters.For instance, you can use @ypnos suggested scanf solution below.