General function to write text files with selected waves and variable sperators

I am trying to write a general function to write to a text a row of comma or tab or colon etc separated variables from a selection of 1d waves of the same length. I have done this for a fixed number of waves with the wave references hard wired into to the code. The fprintf operation has enough flexibility to specify the format needed. But I cannot see a way of doing this with a user specified number of waves. My thoughts have been to build a text wave with the strings containing the names of the waves to be output, and then put it in a loop to set up the wave referencing for each wave. But I can't see how to do using straightforward wave referencing. I have considered perhaps using duplicate or make to set up dummy waves in the function and deleting them at the end but this seems very clunky. I also think I could probably do it in a macro ... any advice welcome
I suspect a loop will be needed at some point. Perhaps you are writing the values of the waves as a CSV row, one row per wave. Iterative over the wave names. Write each wave to a string and concatenate the strings. Alternatively, perhaps you are writing the values of the waves as a CSV column, one column per wave. I'd consider putting the waves in to a (FREE) matrix wave, transpose the matrix, and use the method described above to write contiguous rows.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
If you've figured out a way to do it with fprintf and the wave names hardwired, then the trick may just be to use the Execute operation. You'd create a string that contains the full fprintf command, including the user-specified waves, then Execute that string. You might run into string length limits.
DisplayHelpTopic "The Execute Operation"
This might give you an idea:

Function PrintRow(ww,row)
	Wave/WAVE ww
	Variable row
	
	Variable numWaves = numpnts(ww)
	
	String text = ""
	Variable i
	for(i=0; i<numWaves; i+=1)
		String temp
		Wave w = ww[i]
		Variable value = w[row]
		sprintf temp, "%g", value
		text += temp
		if (i < (numWaves-1))
			text += ","
		endif
	endfor
	Printf "%s\r", text
End

Function Demo()
	Make/O/N=5 wave0=p, wave1=p+1, wave2=p+2
	
	Make/FREE/WAVE/N=3 ww
	ww[0] = wave0
	ww[1] = wave1
	ww[2] = wave2

	PrintRow(ww,1)
End

Thanks for all the suggestions and comments that have led to me successfully writing a very flexible function that does all the things I wanted of it! I built the text wave with names of waves I wanted to output and applied these in a loop to fill a multidimensional wave containing each of the waves for output as columns. I then loop the multidimensional wave a row at a time with sprintl formatting of each data item including the file separators, concatenate these together and output with a fprintf.