473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Block of pointers

I have this structure
struct DIRECTORY{

char nameDir[40];
struct DIRECTORY *parent;
int numSubDir;
struct DIRECTORY *subDir[10];
};

and i allocate it with malloc.Is it possible instead of using an array
of pointers to dynamically allocate a block containing the pointers,so
that if it fills i can realloc it to bigger block?How can this be done?

i tried something like this but doesnt work:
struct DIRECTORY{

char nameDir[40];
struct DIRECTORY *parent;
int numSubDir;
int block;
struct DIRECTORY *subDir[block];
};

Thanks
Nov 15 '05 #1
1 1367
TIT
Nikos Mitas sade:
I have this structure
struct DIRECTORY{

char nameDir[40];
struct DIRECTORY *parent;
int numSubDir;
struct DIRECTORY *subDir[10];
};

and i allocate it with malloc.Is it possible instead of using an array
of pointers to dynamically allocate a block containing the pointers,so
that if it fills i can realloc it to bigger block?How can this be done?

i tried something like this but doesnt work:
struct DIRECTORY{

char nameDir[40];
struct DIRECTORY *parent;
int numSubDir;
int block;
struct DIRECTORY *subDir[block];
};

Thanks


struct DIRECTORY {
char nameDir[40];
struct DIRECTORY *parent;
int numSubDir;
struct DIRECTORY *subDir;
};

#include <stdlib.h>

int main(int argc, char* argv[])
{
struct DIRECTORY d;
d.numSubDir = 10;
d.subDir = malloc(sizeof(struct DIRECTORY) * d.numSubDir);
d.subDir[0].nameDir[0] = 'A';
/* ... */

/* oops out of space */
d.numSubDir += 8;
d.subDir = realloc(d.subDir, sizeof(struct DIRECTORY) * d.numSubDir);

/* now an additional 8 DIRECTORYs exist in the array */
d.subDir[12].nameDir[0] = 'B';

free(d.subDir);

return 0;
}

TIT
Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: ishmael4 | last post by:
hello everyone! i have a problem with reading from binary file. i was googling and searching, but i just cant understand, why isnt this code working. i could use any help. here's the source code:...
9
by: Alfonso Morra | last post by:
I have the following data types: typedef union { long l ; double f; char* s ; void* p ; } Value ; typedef struct {
16
by: Alfonso Morra | last post by:
Hi, I am at the end of my tether now - after spending several days trying to figure how to do this. I have finally written a simple "proof of concept" program to test serializing a structure...
5
by: Alfonso Morra | last post by:
Hi, I am writing a messaging library which will allow me to send a generic message structure with custom "payloads". In many cases, a message must store a non-linear data structure (i.e....
5
by: PCC | last post by:
I am using the Exception Managment Application Block on Windows Server 2003 Enterprise and .NET v1.1. If I use the block with an ASP.NET web wervice or in a web application I get the following...
165
by: Dieter | last post by:
Hi. In the snippet of code below, I'm trying to understand why when the struct dirent ** namelist is declared with "file" scope, I don't have a problem freeing the allocated memory. But...
2
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last reference to the block and thus destory the block is...
7
by: Janis | last post by:
I try to understand what could be the source of a problem with displaying and hiding rows of tables using display:block/none. I've read selfhtml but could not find any hint about that. Any...
4
by: tech | last post by:
Hi, I need to pass a block of say 320 bytes memory between some classes which do various processing on it. The app needs to be quick so i can't keep copying. The simplest way is via pointer...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.