Okay, I built some code that does what you say (however, I'm assuming that you want the input converted to binary int values, hence the sscanf conversion, cf. below).
Note, I would not do this this way, I would use C++ STL containers for this. I particularly don't like the container methodology...