delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/09/02/13:42:31

From: REMOVE_THIS_mimo AT restoel DOT net_AND_THIS
Newsgroups: comp.os.msdos.djgpp
Subject: Re: How to make allocate an array of strings?
Date: Thu, 02 Sep 1999 11:42:10 +0200
Organization: Siemens AG Austria
Lines: 41
Message-ID: <37CE4672.5C9CEE11@restoel.net_AND_THIS>
References: <199909020524 DOT BAA21825 AT delorie DOT com>
NNTP-Posting-Host: 149.202.163.44
Mime-Version: 1.0
X-Trace: scesie13.sie.siemens.at 936265325 10190 149.202.163.44 (2 Sep 1999 09:42:05 GMT)
X-Complaints-To: news AT siemens DOT at
NNTP-Posting-Date: 2 Sep 1999 09:42:05 GMT
X-Mailer: Mozilla 4.08 [de] (WinNT; I)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Dan Gold wrote:

> Okay this is a stupid newbie question but I never actually learned how it
> was done, mayby better suited for a C programming group but I want to
> allocate an array of strings.  I understand how to use strings but not
> create them and not multi-dimensional strings.  Could someone please give
> me an example, the array will hold a list of filenames?
>
> // one dimensional
> char * string = (char *)malloc(string_size * sizeof(char));
>
> // two dimensional
>            ??

this depends on if you know the size of the array before:
1. you know the size:
    char *aszStrings[iNumberOfStrings];
    allocate each with:
    char *aszStrings[i] = [your line...];
2. if you dont know the number you might have to use a linked list:
    typedef struct _node_structStringList{
    char *szString;
    _node_structStringList *next;
    }SNodeStringList;

    and so on...


>
>
> Thanks from ((--Dan|Gold--))
> ps: "Does anyone know of a really comprehensive more advanced C programming
> book?" All I see now of days are C++ books.

maybe changing to c++ is the better idea... you can use string classes which
have been already written and tested a thousand times.

cheers

mimo

- Raw text -


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