prev up next   top/contents search

comp.lang.c FAQ list · Question 12.28b

Q: How can I open files with names like ``file1'', ``file2'', ``file3'', etc., where the numeric part is controlled by a variable? Basically I want ``file%d'', like printf.

A: You want printf's close cousin sprintf, which ``prints'' to a string:

	char filename[FILENAME_MAX];
	sprintf(filename, "file%d", i);
	fp = fopen(filename, "r");

prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North