473,804 Members | 3,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

allocating inner struct array

Given this structure:

typedef struct S
{
struct Inner {
char desc[128];
char *file[MAX_PATH+1];
} *libs;
} S;

The Inner struct has a description string and an array of file strings. I
know the the max length of each file upfront, but not how many files go in
there. As you can see file is now declared as an array of MAX_PATH+1 char
pointers, but I want a dynamic array of static char array. (pfff)
How do I declare and assign to that?
Nov 13 '05 #1
3 3606
Serve Laurijssen wrote:
Given this structure:

typedef struct S
{
struct Inner {
char desc[128];
char *file[MAX_PATH+1];
} *libs;
} S;

The Inner struct has a description string and an array of file strings. I
know the the max length of each file upfront, but not how many files go in
there. As you can see file is now declared as an array of MAX_PATH+1 char
pointers, but I want a dynamic array of static char array. (pfff)
How do I declare and assign to that?

As far as declaration, what about

char (*file)[MAX_PATH + 1];

When you find out how many strings you are going to want to store, you
can use:

file = malloc(sizeof *file); /* easy enough */

and to copy your data, presumably stored filename:

char *filename;

/* fill filename out by whatever means */

strcpy(file[2], filename);

Voila !

--
Bertrand Mollinier Toublet
Currently looking for employment in the San Francisco Bay Area
http://www.bmt.dnsalias.org/employment

Nov 13 '05 #2

"Bertrand Mollinier Toublet" <be************ ***********@ens t-bretagne.fr>
wrote in message news:bf******** ****@ID-168218.news.uni-berlin.de...
As far as declaration, what about

char (*file)[MAX_PATH + 1];


Ok, that wasn't so bad. I actually thought of this before, but in my mind I
translated it into "a pointer to a MAX_PATH+1 array" and I thought that was
wrong.
Nov 13 '05 #3
In <bf**********@n ews3.tilbu1.nb. home.nl> "Serve Laurijssen" <ik@hier.nl> writes:

"Bertrand Mollinier Toublet" <be************ ***********@ens t-bretagne.fr>
wrote in message news:bf******** ****@ID-168218.news.uni-berlin.de...
As far as declaration, what about

char (*file)[MAX_PATH + 1];


Ok, that wasn't so bad. I actually thought of this before, but in my mind I
translated it into "a pointer to a MAX_PATH+1 array" and I thought that was
wrong.


Well, this is exactly what it is: a pointer to an array of MAX_PATH + 1
char.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #4

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

Similar topics

4
745
by: Sameer | last post by:
Hello Group, This is one problem in programming that is troubling me. there is a segmentation fault just before creating memory to a structure ..i.e, just after the "allocating memory " statement. This happens for some inputs and not all. What can be the reason for such fault ?
15
6737
by: fix | last post by:
Hi all, I am writing a program using some structs, it is not running and I believe it is because there's some memory leak - the debugger tells me that the code causes the problem is in the malloc function. Is there any general rules that tell me when to allocate memory? I thought I don't have to if it is a variable that's not a pointer, and I have to if it is. I am a bit confused about the arrays particularly. In normal situations,...
14
3110
by: Gattaca | last post by:
I would like to create a matrix of integers by allocating memory dynamically (malloc or calloc) because i and j are defined during execution of the program. I have got not problem to do this in the static way. For instance, if I want to declare a matrix 20x10 of integers and then to access matrix element: int matrix; int a;
6
2352
by: Everton da Silva Marques | last post by:
Hi, I need to allocate, using malloc(), a single memory block to hold two structures and a variable length string. Is it safe (portable, alignment-wise) to sum up the sizeof's of those structures and add the length of the string, as in this snippet? const char *canonname = "domain.tld";
7
2100
by: boss_bhat | last post by:
Hi all , I am beginner to C programming. I have a defined astructure like the following, and i am using aliases for the different data types in the structure, typedef struct _NAME_INFO { struct _NAME_INFO *Next; ULONG LastId; ULONG Id; PVOID Value;
6
1752
by: toktam | last post by:
Hi guys! I defined a type like this: typedef struct { char *key; int freq; float pr; } TableEntry; and then I have an array of pointers to this struct:
2
1997
by: andrew_nuss | last post by:
Hi, I have an Array<Ttemplate that specializes on T's in my program that inherit from a base class that I've defined called CtorDtorLess. In my array template, I check if boost::is_convertible<T*, CtorDtorLess*> returns true, and then don't use placement new to construct. I've checked in the debugger and everything works with T's that are public classes. However, I also have some "inner classes" that are declared in the private...
6
5187
by: Francois Grieu | last post by:
Hello, I'm asking myself all kind of questions on allocating an array of struct with proper alignment. Is the following code oorrect ? I'm most interested by the statement t = malloc(n*sizeof(r)) and (to a degree) by the surrounding error checking.
10
1770
by: Chris Saunders | last post by:
Here is the declaration of a struct from WinIoCtl.h: // // Structures for FSCTL_TXFS_READ_BACKUP_INFORMATION // typedef struct _TXFS_READ_BACKUP_INFORMATION_OUT { union { //
0
10580
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9157
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7621
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.