Thread: empty vector

  1. #1
    Registered User
    Join Date
    Nov 2018
    Posts
    12

    Post empty vector

    I have this data type:

    Code:
    typedef struct{
         char grapeSet[MAX_GRAPE_SET][MAX_CHAR];
    }tGrapeSet;
    which belongs to these structures:

    Code:
    typedef struct {
        int wineId;
        string wineName;
        tWineType wineType;
        string wineDo;
        float wineAlch;
        int wineConservationYears;
        float winePrice;
        tGrapeSet grapeSet;
    } tWineAblePro;
    
    typedef struct{
        tWineAblePro wines[MAX_WINES];
        int numWinesPro;
    }tWine;
    
    typedef struct {
        tWine *wines;
        int numWines;
        tStock *stock;
        int numBoxes;
        tOrder *orders;
        int numOrders;
    }tCellar;
    then I have a function which adds a wine with grapeSet empty. I'm trying this one, but error "expected expression before
    Code:
    {
    token
    ". Deleting this line, then is ok.

    Code:
    c->wines[c->numWines].wines->grapeSet = {0,0,0,0,0};
    What should I do to add an empty grapeSet?

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,859
    The easiest way is to use a for loop
    Fact - Beethoven wrote his first symphony in C

  3. #3
    Registered User
    Join Date
    Nov 2018
    Posts
    12
    Could you post an example for it?
    many thanks

  4. #4
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,859
    Nothing too hard here...

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #define NUMBER_OF_ROWS 5
    #define NUMBER_OF_COLUMNS 5
    
    typedef struct
    {
        char grapes[NUMBER_OF_COLUMNS][NUMBER_OF_ROWS];
    } fruit;
    
    int main(void)
    {
        fruit *banana;
    
        if(NULL != (banana = malloc(sizeof *banana)))
        {
            int column, row;
    
            for(column = 0; column < NUMBER_OF_COLUMNS; column++)
            {
                for(row = 0; row < NUMBER_OF_ROWS; row++)
                {
                    banana->grapes[column][row] = 0;
                }
            }
            
            free(banana);
        }
        else
        {
            return EXIT_FAILURE;
        }
    
        return EXIT_SUCCESS;
    }
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 03-21-2016, 09:38 AM
  2. Replies: 3
    Last Post: 02-09-2015, 09:56 PM
  3. Replies: 9
    Last Post: 09-22-2013, 07:00 AM
  4. Dereferencing begin() for an empty STL vector
    By rahulss in forum C++ Programming
    Replies: 1
    Last Post: 02-21-2008, 08:43 AM
  5. Struct && vector display empty .....
    By peter_hii in forum C++ Programming
    Replies: 4
    Last Post: 10-02-2006, 03:03 PM

Tags for this Thread