Re: Returning an array of strings in C



wcang79@xxxxxxxxx wrote:
>
> #include <string.h>
> #include <stdio.h>
> #include <stdlib.h>

> strings = (char **) malloc(sizeof(char *) * 100);

strings = malloc(100 * sizeof *strings);

The above way is generally considered a
better style way of writing that.


> strings[i] = malloc(4);

strings[i] = malloc(3 + 1);

This makes it more obvious that string[i]
is intended to be holding a string,
instead of pointing to a string.

--
pete
.



Relevant Pages

  • Re: Selecting hole positions for wind instruments
    ... makers since the ancient Greeks started writing about it. ... See Pythagoras ... Pete ... Prev by Date: ...
    (rec.music.makers.builders)
  • "Type mismatch" error in JScript - newby question
    ... I'm trying to create a simple text file that will allow a string of text to ... The script firstly creates the text file, ... to then open that file for writing into it, I keep on getting a "type ... Prev by Date: ...
    (microsoft.public.scripting.jscript)
  • Re: display strings and numbers
    ... > I'm writing my first m files, and I still have some problem with the ... > How can I display the results of an operation, with a string that mix ... Prev by Date: ...
    (comp.soft-sys.matlab)
  • Re: Counting occurence of character in a string
    ... >> pete wrote: ... Traditionally, the NUL character appears exactly once, at the end of the ... string, and this location is returned in strchr/strrchr. ... Prev by Date: ...
    (comp.lang.c)
  • Extention String returning
    ... I have been writing a program that is designed to return an 8 byte ... string from C to Python. ... Prev by Date: ...
    (comp.lang.python)