-
iteration revisited
Code:
/*writes a (non-NULL terminated) char array to the file f*/
void write_ch_arr(char *c, int i, FILE *f)
{
while (i)
{
putc(c[i], f);
--i;
}
return;
}
now the problem with this is that theoretically, since c can span the entire address range, int might not hold all possible addresses of c.
so what type should I make i?
is the only way to do this with pointer arithmetic? Can I do it with an index and iteration?
of course, this ignores the inefficiency of byte vs. block based transfers.
-
If you want to use an index, I would recommend size_t as your data type.
-
Yes, size_t is guaranteed to cover the same range as a pointer can do in that architecture, so indexing using a size_t type should be fine. size_t is unsigned, which can be useful sometimes and annoying at other times.
--
Mats
-