Use regular expressions.
What you are doing would be better done in Perl or another dynamic language with built in regex support, but you can do it in C with the PCRE (Perl Compatible Regular Expression) library.
It's probably a bad idea to read the entire file in at once into a static structure. It doesn't scale, it's wasteful, and it's begging for problems (EG buffer overflows). Process your input line by line and dynamically allocate storage as it's needed.
in Perl:
#!/usr/bin/perl
use strict;
use warnings;
my @answers; # array of answers
while (my $line = <>) { # read from STDIN, breaking on newlines
my ($number) = $line =~ /v (\d{3})/; # match and capture
if ( defined($number) ) {
push @answers, $number; # append number to array
}
}
# do what you want with @answers
print join("\n", @answers), "\n";
The key bit is the regular expression /v (\d{3})/
C implementation is left as an exercise for the reader. Why write 100 lines of C when 12 lines of Perl will get the job done?