Could anyone suggest a short way to open a sequence of files one at a
time using a for loop?. Say files of the form
filename.0,filename.1,filename.2,...,filename.n.
Would it work to cast the integer into char and run a for loop on the
outside?
Richard has already answered your larger question, but I thought I'd
note that char is an integer type, and you can use it in the
controlling expression of a for loop. While I don't see any
particular reason to do it this way, for the particular case of a
single decimal digit you could do something like:
char Num;
for (Num = '0'; Num <= '9'; Num++)
{
char Filename[20];
sprintf(Filename, "filename.%c", Num);
...
This works for decimal digits because they're guaranteed to be
positive, contiguous, and in order. As I noted above, though,
there's no advantage I can see to doing it this way; I just wanted to
point out that the controlling expression of a for loop doesn't have
to involve an int variable.
--
Michael Wojcik (e-mail address removed)
Against all odds, over a noisy telephone line, tapped by the tax authorities
and the secret police, Alice will happily attempt, with someone she doesn't
trust, whom she can't hear clearly, and who is probably someone else, to
fiddle her tax return and to organise a coup d'etat, while at the same time
minimising the cost of the phone call. -- John Gordon