delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/05/28/03:26:45

Message-ID: <F6E7432DD437D511AD92009027C3AAC466B978@headoffice.umgeni.co.za>
From: Scott Sinclair <scott DOT sinclair AT umgeni DOT co DOT za>
To: djgpp AT delorie DOT com
Subject: RE: Re(2): Array of poiters to an Array
Date: Mon, 28 May 2001 09:41:30 +0200
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2653.19)
Reply-To: djgpp AT delorie DOT com

Hi
>Sorry for the silence, we had a long WE last week from Wednesday to
>Sunday, 

>If it is not char *argv[] but a local variable, what should I do?

>>> Hi all,
>>
>>> This question is about C and not about djgpp itself. How to add a string
>>> to char * argv[] for example?
>>
>>Depends largely on where that argv[] came from.  If it's the parameter
>>of main(), you can't --- that's unmodifiable memory, and you can't
>>push anything else into it without risking problems.

One way is to try declaring an array of pointers

char **array_of_pointers[];

Now you need to malloc enough space for the number of string pointers you
need

array_of_pointers = (char **)malloc(number_of_strings*sizeof(char *));

Next allocate each of these pointers enough space to hold the required
string

array_of_pointers[0] = (char *)malloc(size_of_string1*sizeof(char));
array_of_pointers[1] = (char *)malloc(size_of_string2*sizeof(char));
etc...

You can fill these arrays with code like

array_of_pointers[0] = "my string";

Hope this helps ?:)

bye
-----------------------------------------------------
Scott Sinclair
Water Resources Planning
Umgeni Water

e-mail: scott DOT sinclair AT umgeni DOT co DOT za
Tel: (+27 33) 341 1133


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019