M
Mark F. Haigh
gtippery wrote:
[OT]
The limits change depending on the compiler / memory model combination.
I know there's one out there (a huge model variant) using 16 bit int
and 32 bit size_t. Can't remember which compiler, and don't care to--
hopefully my DOS programming days are far behind me (pun intended),
never to return.
The standard states (7.17) that "size_t [...] is the unsigned integer
type of the result of the sizeof operator". Use it like any other
integral type, including in for statements and subscripting operators
(ie []). Generally, size_t is a better choice than int for array
subscripting.
So, making a few simple modifications to my previously posted code:
---snip---
#include <stdio.h>
#define MAXCOL 2
#define NAMLEN 8
#define EXTLEN 3
struct NameExt
{
char name[NAMLEN];
char ext[EXTLEN];
};
int main(void)
{
/* Some sample filenames */
struct NameExt list[] = {
{ "One ", "1 " },
{ "TwoTwo ", "22 " },
{ "ThreeThr", "333" },
{ "Four ", "4 " },
{ "FiveFive", "55 " },
{ "SixSixSi", "666" },
};
/* Print the array out */
size_t i;
for(i = 0; i < sizeof(list) / sizeof(list[0]); i++)
printf("%-*.*s.%-*.*s%s",
NAMLEN, NAMLEN, list.name,
EXTLEN, EXTLEN, list.ext,
(i + 1) % MAXCOL ? " " : "\n");
return 0;
}
--- snip ---
[mark@icepick ~]$ gcc -Wall -O2 -ansi -pedantic foo.c -o foo
[mark@icepick ~]$ ./foo
One .1 TwoTwo .22
ThreeThr.333 Four .4
FiveFive.55 SixSixSi.666
I believe that's what you're looking for. That's the simplest code I
can think of off the top of my head.
Mark F. Haigh
(e-mail address removed)
elements),The platform limit is 64KB for any one item (i8086). The array would
be the limiting factor in this case (at something over 5,000
[OT]
The limits change depending on the compiler / memory model combination.
I know there's one out there (a huge model variant) using 16 bit int
and 32 bit size_t. Can't remember which compiler, and don't care to--
hopefully my DOS programming days are far behind me (pun intended),
never to return.
If size_t isn't actually an int (of some standard type), isn't that
going to be a problem in the for()? I thought the index variable had
to be an integer or enumeration.
The standard states (7.17) that "size_t [...] is the unsigned integer
type of the result of the sizeof operator". Use it like any other
integral type, including in for statements and subscripting operators
(ie []). Generally, size_t is a better choice than int for array
subscripting.
So, making a few simple modifications to my previously posted code:
---snip---
#include <stdio.h>
#define MAXCOL 2
#define NAMLEN 8
#define EXTLEN 3
struct NameExt
{
char name[NAMLEN];
char ext[EXTLEN];
};
int main(void)
{
/* Some sample filenames */
struct NameExt list[] = {
{ "One ", "1 " },
{ "TwoTwo ", "22 " },
{ "ThreeThr", "333" },
{ "Four ", "4 " },
{ "FiveFive", "55 " },
{ "SixSixSi", "666" },
};
/* Print the array out */
size_t i;
for(i = 0; i < sizeof(list) / sizeof(list[0]); i++)
printf("%-*.*s.%-*.*s%s",
NAMLEN, NAMLEN, list.name,
EXTLEN, EXTLEN, list.ext,
(i + 1) % MAXCOL ? " " : "\n");
return 0;
}
--- snip ---
[mark@icepick ~]$ gcc -Wall -O2 -ansi -pedantic foo.c -o foo
[mark@icepick ~]$ ./foo
One .1 TwoTwo .22
ThreeThr.333 Four .4
FiveFive.55 SixSixSi.666
I believe that's what you're looking for. That's the simplest code I
can think of off the top of my head.
Mark F. Haigh
(e-mail address removed)