Variable number of arguments to functions

Frank Burleigh burleigh at silver.bacs.indiana.edu
Wed Jun 21 03:28:23 AEST 1989


I am (very) new to C, and need suggestions from the net on the
proper way(s) to handle this problem.  It involves reading files
whose lines may have a variable number of space-separated values.
 
I have several pairs of files (FILEA, FILEB).  FILEA of each pair
contains several groups of lines with a constant (VALUES) number
of values on each line throughout the file.  FILEB contains one
line with VALUES values corresponding to each group of lines in
FILEA.  The ith value on the jth line in FILEB is used to adjust
the ith value on each line in the jth group of lines in FILEA.
 
The vexing problem for me is that each pair of FILEA and FILEB
files has a different number of values on the input lines.  I
could compile different versions of the program to accommodate
each pair, but that seems less than elegant.
 
Apparently this is a problem to be solved by passing a variable
number of arguments to vscanf() and vprintf() with the va_...
macros in <stdarg.h>, but the procedures for this sort of
application are not clear to me (from KR2 or Turbo C reference).
 
I'm especially eager to see sample code to help me through this.
 
Thanks in advance.

Frank Burleigh  burleigh at silver.bacs.indiana.edu
USENET: ...rutgers!iuvax!silver!burleigh BITNET: BURLEIGH at IUBACS.BITNET
Department of Sociology, Indiana University, Bloomington, Indiana 47405



More information about the Comp.lang.c mailing list