Thread: dynamic arrays and structures

  1. #1
    Registered User
    Join Date
    Oct 2002

    dynamic arrays and structures

    I'm trying to set up a structure within a structure, but there's also two dynamic arrays inside:

    struct Sentence {
    int numwords; 
    char **words;
    struct Document {
    int numLines;
    Sentence *sentences;
    } Doc;
    that's a structure (Doc) with a dynamic structure inside (Sentence *sentences) with a dynamic array inside that (char **words)

    The problem is I can't seem to access the char **words portion of the array.

    I've set up:
    int len=0;
    Doc.sentences = new Sentence[len];
    However, I can't seem to be able to figure how to dynamically allocate memory for **words so that it becomes an array of pointers.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
      char **strings;
      strings = new char*[15];
      int i;
        for(i = 0; i < 15; i++) {
          strings[i] = new char[100];
          sprintf(strings[i], "%i\n", i+1);
          printf("%s", strings[i]);
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  2. errors with arrays and structures
    By ssjnamek in forum C++ Programming
    Replies: 4
    Last Post: 03-03-2002, 11:48 PM
  3. Newbie Help (Arrays, Structures, Functions,Pointers)
    By tegwin in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2002, 06:29 PM
  4. Concerning Dynamic Arrays
    By CeeCee in forum C Programming
    Replies: 15
    Last Post: 11-25-2001, 02:19 PM