Re: Dinamically allocate array of array of structures
- From: Frederick Gotham <fgothamNO@xxxxxxxx>
- Date: Thu, 31 Aug 2006 14:55:29 GMT
valerio posted:
Hello all
I would like to dinamically allocate an array of array of structures.
I.e. a two-dimensional array of structures.
To explain this:
struct file{ char* fileName,int inode) myfiles[];
struct file{ char* fileName,int inode) mydirs[][];
Is this your first day learning C? Get the syntax right.
The amount of files in each directory will have to be constant:
#define FILES_PER_DIR 5
#define QUANTITY_DIRS 2
#include <stdlib.h>
typedef struct File {
char const *name;
} File;
File dir1[] = {{"a.exe"},{"b.exe"},{"c.exe"},{"d.exe"},{"e.exe"}};
File dir2[] = {{"a.bat"},{"b.bat"},{"c.bat"},{"d.bat"},{"e.bat"}};
File mydirs[QUANTITY_DIRS][FILES_PER_DIR];
int main(void)
{
unsigned i,j;
memcpy(mydirs,dir1,sizeof dir1);
memcpy(mydirs+1,dir2,sizeof dir2);
for(i=0; i!=QUANTITY_DIRS; ++i)
{
for(j=0; j!=FILES_PER_DIR; ++j)
{
puts(mydirs[i][j].name);
}
}
return 0;
}
--
Frederick Gotham
.
- References:
- Dinamically allocate array of array of structures
- From: valerio
- Dinamically allocate array of array of structures
- Prev by Date: Re: compiling service ?
- Next by Date: Re: c code reusability
- Previous by thread: Dinamically allocate array of array of structures
- Next by thread: Re: Dinamically allocate array of array of structures
- Index(es):
Relevant Pages
|