473,387 Members | 3,033 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,387 software developers and data experts.

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 3585
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***********************@enst-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**********@news3.tilbu1.nb.home.nl> "Serve Laurijssen" <ik@hier.nl> writes:

"Bertrand Mollinier Toublet" <be***********************@enst-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
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 "...
15
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...
14
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...
6
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...
7
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 {...
6
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
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...
6
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 =...
10
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
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.