Mail Archives: djgpp/2001/05/28/03:26:45
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 -